Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

gitignore .env not working – remove cache from git history

gitignore .env file not working - skpaul.me

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.


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.

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.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Wordpress Social Share Plugin powered by Ultimatelysocial