Skip to content

Instantly share code, notes, and snippets.

@bquorning
Created April 6, 2013 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bquorning/5325718 to your computer and use it in GitHub Desktop.
Save bquorning/5325718 to your computer and use it in GitHub Desktop.
Here's the script I use to remove my merged branches, both remote and local. Disclaimer: Don’t blame me if you use this script to remove something you wanted do keep. Maybe add the `-n` flag to `git push` while you’re trying out how the script works. If in trouble, read [man git-reflog](http://git-scm.com/docs/git-reflog).
git checkout master
git pull
git remote prune origin
git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin
git branch --merged | grep -v "\* master" | xargs git branch -d
# That was actually a somewhat simplified version. Here's what I really use:
git checkout master && git pull && (git remote prune origin && git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin) & ; git branch --merged | grep -v "\* master" | xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment