Progress:
TIER 1 · MODULE 11· Basics

git rm

Delete from the working tree and stage the removal.

🎯 What & why

Remove a tracked file from the working tree and stage the removal. One operation instead of two.

🧠 Mental model

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.

🛠️ Synopsis

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
       [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]
       [--] [<pathspec>...]

🎚️ Switches & options

FlagWhat it does
-rRecurse into directories.
--cachedRemove from index only — keep the file on disk.
-f, --forceOverride the safety check that blocks removal of files with staged or unstaged changes.
-n, --dry-runShow what would happen, do nothing.

💡 Use cases

🧪 Examples

Remove a tracked file.
$ git rm secret.txt
Untrack a file you accidentally added (keep on disk).
$ git rm --cached config/local.yaml
Remove a directory recursively.
$ git rm -r build/

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.