
If you’ve ever added a folder to .gitignore and then wondered “Why is Git still tracking this?”, you’ve just run into one of Git’s most common (and confusing) behaviours.
The short answer: .gitignore is not retroactive.
Let’s unpack what that means and how to fix it cleanly.
The core idea: Git tracks files, not rules
Git has two important concepts:
- Working tree — files on your disk
- Index (staging area) — files Git is actively tracking
.gitignore only tells Git:
“Don’t track new files that match these patterns.”
If a file or folder was already committed, Git will continue tracking it forever — unless you explicitly tell Git to stop.
So adding something .gitignore does not untrack it.
This is by design.
The correct fix (safe and canonical)
If you want Git to stop tracking a folder but keep it on your machine, do this:
git rm -r --cached path/to/folder
git commit -m "Stop tracking folder"
Example:
git rm -r --cached outputs/
git commit -m "Ignore generated outputs"
What this does:
- Removes the folder from Git’s index
- Keeps all files intact locally
- Makes
.gitignoreeffective going forward
No data loss. No hacks.
Verifying the result
After committing, run:
git status
The folder should no longer appear.
You can also confirm with:
git ls-files | grep outputs
If nothing shows up, Git is no longer tracking it.
Common mistakes to avoid
- ❌
rm -rf outputs/→ deletes your files - ❌
git rm outputs/→ deletes files locally - ❌ Expecting
.gitignorealone to fix tracked files
Remember: Git never forgets unless you explicitly tell it to.
A special note for large or sensitive files
If the folder was already pushed to a remote and contains:
- Large files
- Checkpoints
- Sensitive data
Then, removing it from tracking is not enough — you may need to rewrite Git history using tools like git filter-repo.
That’s a more advanced (and destructive) operation, but sometimes necessary. Check the next article for the abovementioned operation
How to Remove Large Files from Git History
*(and Why git rm --cached Seems to Work)*medium.com
TL;DR
.gitignoreonly affects untracked files- To stop tracking an existing folder:
git rm -r --cached folder/ git commit - This is expected Git behaviour, not a bug
Once you understand the index vs working tree distinction, Git becomes far less mysterious — and far more predictable.
Originally published on Medium.