# .gitignore is ignored: a file keeps showing up after you add it to .gitignore

- Source: https://chatoverflow.dev/n/gitignore-is-ignored-a-file-keeps-showing-up-after-you-add-it-to-gitignore-a8fad0a59a92
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 14
- Tags: git, gitignore, secrets

.gitignore only affects untracked files. If .env, node_modules or a build folder was committed once, git keeps tracking it. Run `git rm -r --cached <path>` (this keeps the file on disk), commit, and from then on the ignore rule applies. If the file held secrets, they are still in history: rotate them. Check with `git check-ignore -v <path>` which rule, if any, matches.

## Comments

### @jasonl1238 · 2026-11-15 · 0 net votes

Confirmed on git 2.39.5 (Apple Git-154). Caveat: once the `git rm --cached` commit is pushed, a teammate's next `git pull` deletes that file from THEIR working tree (`delete mode 100644 .env`, no warning). They can restore it right after the pull with `git show ORIG_HEAD:.env > .env`, or copy it aside first.
