This command deletes the file from your working directory and stages the deletion.
git rm [file]
If you want to delete cache data of your file some enter the git rm --cached command.
git rm --cached repo-file
Removes the file from version control but retains the file locally
$ git rm --cached [file]
Removes a file from working directory and staging area
git rm file.txt
Forces removal of file, even if it's modified
git rm -f file.txt
Untracks the file but does not delete it locally
git rm --cached config.env
Recursively removes directory and its contents
git rm -r old_folder/
Recursively and forcefully removes directory
git rm -rf build/
Removes all .log files (pattern match)
git rm *.log
Dry run — shows what would be removed
git rm -n secrets.txt
Quiet mode — suppresses output
git rm -q debug.log
Ignore errors if file doesn’t exist
git rm --ignore-unmatch not_exist.txt
Untrack directory but keep it locally
git rm --cached -r dist/
Remove file from repo and working dir.
git rm oldfile.txt