git rm
Removes files from the working directory and the staging area.
Syntax
git rm [<options>] <file>...
Options
- --cached: Removes the file only from the staging area, keeping it in the working directory
- -r: Allows recursive removal of directories
- -f / --force: Forces removal of files that have local modifications
- --dry-run: Shows what would be removed without actually removing
Example
git rm obsolete.txt git rm --cached secret.env git rm -r old-directory/
Tip
Use --cached to stop tracking a file without deleting it from disk.