Skip to content

Untrack Already Committed Files

If you accidentally committed a file or directory that should be ignored, adding it to .gitignore is not enough. You must also remove it from Git's index without deleting it locally.

The Quick Guide

1. Update .gitignore First, make sure the path is correctly added to your .gitignore file.

2. Remove the file/directory from Git's cache Run the following command. The --cached flag ensures the file is NOT deleted from your local disk.

# For a single file
git rm --cached path/to/file.ext

# For a directory (recursive)
git rm -r --cached path/to/directory/

3. Commit the changes Running the command above stages a deletion. You must commit this change to finalize it.

git commit -m "chore: untrack <file/directory>"

Note: Your local files will remain intact, but Git will stop tracking them.