DEV Community

Shawon Saha
Shawon Saha

Posted on

Remove accidentally pushed .env file from all git commits

Make sure to safely backup the .env file first. Because this command will delete it from your system

git filter-branch --index-filter 'git rm --cached --ignore-unmatch .env' HEAD

Enter fullscreen mode Exit fullscreen mode
git push --force
Enter fullscreen mode Exit fullscreen mode

If you get error like this
Image description

Run this command and froce push

git update-ref -d refs/original/refs/heads/main
Enter fullscreen mode Exit fullscreen mode

Top comments (0)