gitignore .env not working – remove cache from git history
Problem:
I want git to ignore the .env file that contains my local development environment configuration. I’m using git in VS Code editor. This is how the .env file is listed in the .gitignore file.
*.env
.env
But it keeps syncing with the git repository. And every time the code has been merged, the staging and production environments have been messed up.
Solution:
I do some research online and find this solution.
As we already have added the file to be cached/tracked, so we need to remove it from caching/tracking.
git rm .env –cached
I hope you find this useful and time-saving; please let me know in the comments.