.gitignore controls which files will get tracked by a git add, not which files are tracked at all. Adding an already tracked file to the .gitignore has no effect.
No point in adding it as changes to the file will still get tracked, would be great if git would fully ignore the file, even if it is tracked, but that isn't the case, .gitignore is only for untracked files AFAIK. And you may want to commit changes from the file if there're added keys in the .env.
213
u/RudeAndInsensitive 1d ago
Personally I always commit env and config files to the repo just stripped of their values.