Completely remove a file from Git history permalink
To remove the file altogether, we can use the following command. Assuming .env is the file to remove
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD
You will get some warnings about this messing up your history as this goes through your whole history and 100% removes its occurrence.
To push this, you have to run the following command.
git push --force