Removing files

To remove a file (say file2.txt) from our repository we could use rm file2.txt. The problem with this command is that is not a git command. So the file will be removed from the Working Directory, but not from the Staging Area. It's OK to do it this way, just remember that since the file is still in the Staging Area, you'll need to git add it and then git commit it. Since this is such a common operation, there's a Git version of the remove command that does everything in one step.

You can check which files are in the Staging Area by running

git ls-files

You should see both files in there: file1.txt and file2.txt. Now to delete file2.txt we use

git rm file2.txt

If you run git ls-files again, you should see that file2.txt is no longer in the Staging Area. And if you run ls you'll see that neither is file2.txt in the Working Directory. We have successfully delete file2.txt in one command.

Removing files 1