Stop tracking a committed file
Medium risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Removes a file from git tracking while keeping it on disk, and adds it to .gitignore so it is not accidentally committed again.
gitgitignoreuntrack
Parameters
Path of the tracked file to stop tracking.
Commands
Confirm the file is currently tracked
git ls-files --error-unmatch <path>Remove the file from the index while keeping it on disk
git rm --cached <path>Ignore the file so it is not staged again
echo "<path>" >> .gitignoreStage the .gitignore change alongside the removal
git add .gitignoreCommit the removal and the ignore rule together
git commit -m "Stop tracking <path>"Verification
git check-ignore <path>Prints the path, confirming it is ignored; the file still exists on disk.
Undo
Revert the commit, restoring tracking and removing the ignore rule
git revert HEADPitfalls
- The file's history remains in the repository; this does not purge past commits containing it.
- Collaborators who pull this change keep their local copy, but git deletes it on some checkout paths — warn them.
- Committed secrets require history rewriting and rotation, not just untracking.