Nuke git history
If you add a .env or some other password to git by mistake, you’ll want to remove it.
Remove current version
Section titled “Remove current version”Remove the file from the index (the repo), but keep it on your computer (.env in this example)
git rm --cached .envCommit the change
git commit -m "Remove sensitive config from source control"Push to your remote (GitHub/GitLab/etc)
git push origin mainClean git history
Section titled “Clean git history”The above only removes the file going forward. If you want to remove it from the git history, you’ll need to use git-filter-repo.
Install git-filter-repo
Section titled “Install git-filter-repo”Debian based distros
sudo apt install git-filter-repoArch based distros
sudo pacman -S git-filter-repoFedora based distros
sudo dnf install git-filter-repoCleanup
Section titled “Cleanup”git filter-repo --path .env --invert-pathsRelink
Section titled “Relink”git remote add origin <your-repo-url>git push origin --force --all