How to Remove a File from a Git Repository (with git rm)
The git rm command removes a file from the Git repository. Unlike simply deleting a file in your editor or file browser — which only removes it from the filesystem — git rm also stages the removal so it's included in your next commit.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Remove a File from the Repository and Filesystem
To delete a file from both the Git repository and the disk:
$ git rm file1.txt
Stop Tracking a File Without Deleting It
Use --cached to remove a file from Git's tracking while keeping it on your filesystem. This is useful when you accidentally committed a file you now want to add to .gitignore:
$ git rm --cached file2.txt
Remove a Directory Recursively
Add -r to remove a folder and all its contents:
$ git rm -r old-directory/
Preview Before Removing
When removing multiple files with a glob pattern, use --dry-run (or -n) to see what would be deleted without actually doing it:
$ git rm css/* --dry-run
rm 'css/about.css'
rm 'css/general.css'
No Command Line Needed
Removing Files in Tower
In case you are using the Tower Git client, removing files is very easy: select the "Move to Trash" option and Tower will automatically mark the file as "deleted" in Git. And if you change your mind, hit CMD+Z (or CTRL+Z on Windows) to restore the file!
In Tower, you can use this keyboard shortcut to effortlessly undo almost any action in Git, making it easy to revert changes.
Download the Cheat SheetFree
Get 18 of our most popular Cheat Sheets in one handy ZIP!

Thanks! Please Check Your Inbox!
Want to win one of our awesome Tower shirts?
Tell your friends about the package!
