[git] Why use 'git rm' to remove a file instead of 'rm'?

On SVN, removing something from the filesystem directly (rather than using svn) created a load of headaches.

I haven't found this to be an issue when using git, but I notice that git has it's own rm implementation (git rm).

What is the difference between rm and git rm?

This question is related to git

The answer is


When using git rm, the removal will part of your next commit. So if you want to push the change you should use git rm


Removing files using rm is not a problem per se, but if you then want to commit that the file was removed, you will have to do a git rm anyway, so you might as well do it that way right off the bat.

Also, depending on your shell, doing git rm after having deleted the file, you will not get tab-completion so you'll have to spell out the path yourself, whereas if you git rm while the file still exists, tab completion will work as normal.


Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory.

Here's how you might delete a file using rm -f and then remove it from your index with git rm

$ rm -f index.html
$ git status -s
 D index.html
$ git rm index.html
rm 'index.html'
$ git status -s
D  index.html

However you can do this all in one go with just git rm

$ git status -s
$ git rm index.html
rm 'index.html'
$ ls
lib vendor
$ git status -s
D  index.html

git rm will remove the file from the index and working directory ( only index if you used --cached ) so that the deletion is staged for next commit.


However, if you do end up using rm instead of git rm. You can skip the git add and directly commit the changes using:

git commit -a


Adding to Andy's answer, there is additional utility to git rm:

  1. Safety: When doing git rm instead of rm, Git will block the removal if there is a discrepancy between the HEAD version of a file and the staging index or working tree version. This block is a safety mechanism to prevent removal of in-progress changes.

  2. Safeguarding: git rm --dry-run. This option is a safeguard that will execute the git rm command but not actually delete the files. Instead it will output which files it would have removed.