Michael Boutin

Stop tracking a file that's already committed

bashMay 6, 2026

Adding a path to .gitignore does not untrack files git already knows about. Use git rm --cached to drop it from the index while keeping the local copy.

.gitignore only prevents new files from being tracked. If a file was committed before you ignored it, git keeps tracking changes to it. To stop tracking it without losing the local copy, remove it from the index with --cached.

terminal
echo "components.json" >> .gitignore
git rm --cached components.json
git commit -m "Stop tracking components.json"

The file stays in your working tree, but future changes are ignored. Anyone who pulls the commit will see the file deleted from their checkout, so this is a one-way move: do it intentionally, on a branch, with the team in the loop.

Liked this? Get the next one in your inbox.

One email every other Tuesday. Engineering, product, and what I'm shipping. Unsubscribe anytime.

No spam. See the privacy policy.

  • bash

    Remove node_modules from a git repo

    Stop tracking a committed node_modules folder and ignore it going forward.

    May 10, 2026
  • bash

    Change a git remote's URL

    Point an existing remote at a new URL without removing and re-adding it.

    May 10, 2026
  • bash

    Delete local and remote git branches

    Delete branches one at a time, or sweep up local branches whose upstream has already been deleted.

    May 10, 2026