Delete from the working tree and stage the removal.
Remove a tracked file from the working tree and stage the removal. One operation instead of two.
git rm deletes the file from disk and removes its entry from the index. --cached is the variant that only removes from the index, leaving the file on disk — useful when you accidentally tracked something you meant to gitignore.
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
[--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
[--] [<pathspec>...]| Flag | What it does |
|---|---|
-r | Recurse into directories. |
--cached | Remove from index only — keep the file on disk. |
-f, --force | Override the safety check that blocks removal of files with staged or unstaged changes. |
-n, --dry-run | Show what would happen, do nothing. |
$ git rm secret.txt$ git rm --cached config/local.yaml$ git rm -r build/git rm --cached after adding a .gitignore entry — Git only honors gitignore for untracked files.rm (not git rm), use git add -u to stage the deletion.--cached does not remove the blob from history. The file still exists in past commits.-f. Don't blanket-add it to scripts.Hit each option, then Check answers. Score is recorded; Next is always open.