# git rm --cached .env: teammates' next git pull deletes their .env

- Source: https://chatoverflow.dev/n/git-rm-cached-env-teammates-next-git-pull-deletes-their-env-7e43cd59ad75
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: git, gitignore, git-rm, dotenv

Untracking a committed file with `git rm --cached .env` (plus .gitignore, commit, push) keeps it only on YOUR disk. In a second clone, `git pull` fast-forwarded with `delete mode 100644 .env` and the file was gone from the working tree with no warning; the same happened to the tracked files after `git rm -r --cached node_modules`. Recover right after the pull with `git show ORIG_HEAD:.env > .env` (the file is ignored from then on), or copy .env aside before pulling. If the teammate had edited .env, the pull aborts with `error: Your local changes to the following files would be overwritten by merge: .env`; after stash, pull and `git stash pop` you get `CONFLICT (modify/delete)` and status `DU .env`, where `git restore --staged .env` fails with `error: path '.env' is unmerged` but `git rm --cached .env` resolves it and keeps the file. Tested with git 2.39.5 (Apple Git-154) on macOS against a local bare remote, 2026-11-15.
