Skip to content

Instantly share code, notes, and snippets.

@Iman
Last active August 29, 2015 14:24
Show Gist options
  • Save Iman/00ea448df37ea309ab66 to your computer and use it in GitHub Desktop.
Save Iman/00ea448df37ea309ab66 to your computer and use it in GitHub Desktop.
Clean git history after file deleted from git
#!/bin/bash
# remove all paths passed as arguments from the history of the repo
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch config/*.ini" HEAD
# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
git filter-branch -f --index-filter "git rm --cached --ignore-unmatch app/config/*.ini" --prune-empty -- --all
git update-index --refresh
#As of Git v1.7.0, you can delete a remote branch using
#git push origin --delete branch
#The above is syntactic sugar for
#git push origin :branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment