Stop tracking a file that's already committed
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.
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.