Tuesday, July 12, 2011

Pruning GitHub / merged

Tired of all your outdated branches? Now there's a way..
git branch --merged | grep -v "^* " | awk '{print "git branch -d " $1 "; git push origin :" $1}' | sh
What it boils down to:
git branch --merged = shows all the merged ones
grep -v "^*" = excludes the current branch (can't delete a branch you're currently on)
awk '{print "git branch -d " $1 "; git push origin :" $1}' = delete merged branch and delete it on GitHub.
If you want to double-check, take away the last "| sh" to verify everything works. You have been warned.

You may get some errors if the branch that has already been merged no longer exists on your GitHub origin..

No comments:

Post a Comment