Skip to content

Instantly share code, notes, and snippets.

@midwire
Last active August 15, 2022 20:22
Show Gist options
  • Save midwire/8d19032487721d23106e96389b8b54f3 to your computer and use it in GitHub Desktop.
Save midwire/8d19032487721d23106e96389b8b54f3 to your computer and use it in GitHub Desktop.
[Git remove file from history] #git #shell
# Example file is `.env`
# Remove the file from the disk
# Add the file path to .gitignore
echo ".env" >> .gitignore
# Permanently remove it from the git history
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD
# Force push
git push --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment