Git - Stop Tracking Files While Keeping Them Locally

Goal

Stop Git from tracking a file or folder that’s already committed, while keeping it in your working directory.

Context

.gitignore only prevents untracked files from being added. Files already tracked by Git will continue to be tracked even after adding them to .gitignore.

Solution

Remove the file from Git’s index while keeping it locally:

git rm --cached <file>

For folders:

git rm -r --cached <folder>

The file removal is staged immediately but only takes effect in the repository after you commit:

git commit -m "Stop tracking <file>"

Warning

Other developers will lose these files on their next git pull. The files are removed from their working directory, not just untracked. Make sure they back up local versions or add the files to .gitignore before pulling.