git rm Remove files from the repository and your folder
Deletes a file and stages the deletion in one step, so the next commit records that the file is gone. It also stops Git tracking the file if you keep it.
Synopsis
git rm [OPTION]... FILE...
Common options
| Option or form | What it does |
|---|---|
--cached | Stop tracking the file but leave it on your disk |
-r | Remove a folder and its contents |
-f | Force removal even when the file has local changes |
-n, --dry-run | Show what would be removed without doing it |
Examples
git rm old-notes.txt
rm 'old-notes.txt'
git rm --cached .env
git rm -r build/
git rm -rn build/
Notes
- If you already deleted the file by hand, git rm FILE or git add -A records the deletion.
- Use --cached then add the file to .gitignore for something you committed by mistake, such as a local config. The old commits still contain it.
- Secrets committed once remain in history. Rotate them as well as removing them.
See also
Last reviewed 2026-10-09.