Blame | Last modification | View Log | RSS feed
#!/usr/bin/env bash## mfclean## Prune all your merged branches and any branches whose remotes are gone# Great way to clean up your branches after messing around a lot#KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2"echo "Fetching latest upstream and origin..."git fetch upstreamgit fetch originechoecho "Pruning Merged Branches..."git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -dechoecho "Pruning Remotely-deleted Branches..."git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -Decho# List fork branches that don't match local branchesecho "You may want to remove (or checkout) these refs..."comm -23 \<(git branch --all | sed 's/^[\* ] //' | grep origin/ | grep -v "\->" | awk '{ print $1; }' | sed 's/remotes\/origin\///') \<(git branch --all | sed 's/^[\* ] //' | grep -v remotes/ | awk '{ print $1; }') \| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; print ""; }'echo