Stop tracking a file without deleting it

You committed .env or a build folder. Get it out of git but keep it on disk.

SNP 064 #A42 Filed git

shell
echo '.env' >> .gitignore
git rm --cached .env
git commit -m "Stop tracking .env"

--cached removes it from the index only. The file stays where it is; git just forgets about it from now on. For a folder add -r:

shell
git rm -r --cached dist

Two things: the file is still in the old commits, so if it was a secret, rotate it. And when teammates pull, git deletes their copy of the file, so warn them.