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:
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.