Search code examples
gitgit-rm

running 'git rm' for a new file?


I have done the following (in order to learn git rm).

Created an empty repository on an empty folder. Created a file called test.txt, modify it and then run the following (with the consequent results).

git rm test.txt -> `fatal: pathspec 'test.txt' did not match any files`

git add test.txt && git rm test.txt -> 
error: 'test.txt' has changes staged in the index
                   (use --cached to keep the file, or -f to force removal)

So, my question is:

When would git rm test.txt be actually useful?


Solution

  • When would git rm test.txt be actually useful?

    When you have already added and committed the file to your repository. The docs tell us that git rm is used to:

    Remove files from the index, or from the working tree and the index.