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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more