2016-04-19 04:18:35 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfprune
|
|
|
|
#
|
|
|
|
# Prune all your merged branches and any branches whose remotes are gone
|
|
|
|
# Great way to clean up your branches after messing around a lot
|
|
|
|
#
|
|
|
|
|
2017-04-21 02:10:41 +00:00
|
|
|
echo "Fetching latest upstream and origin..."
|
|
|
|
git fetch upstream
|
|
|
|
git fetch origin
|
|
|
|
echo
|
|
|
|
|
2016-04-19 04:18:35 +00:00
|
|
|
echo "Pruning Merged Branches..."
|
|
|
|
git branch --merged | egrep -v "^\*|RC|RCBugFix|dev" | xargs -n 1 git branch -d
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo "Pruning Remotely-deleted Branches..."
|
|
|
|
git branch -vv | egrep -v "^\*|RC|RCBugFix|dev" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
|
|
|
|
echo
|
|
|
|
|
2017-04-21 02:10:41 +00:00
|
|
|
echo "You may want to remove (or checkout) these refs..."
|
2016-04-19 04:18:35 +00:00
|
|
|
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; }') \
|
2017-04-21 02:10:41 +00:00
|
|
|
| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; }'
|
2016-04-19 04:18:35 +00:00
|
|
|
echo
|