2016-04-18 23:18:35 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2017-05-05 00:46:39 -05:00
|
|
|
# mfclean
|
2016-04-18 23:18:35 -05:00
|
|
|
#
|
|
|
|
# Prune all your merged branches and any branches whose remotes are gone
|
|
|
|
# Great way to clean up your branches after messing around a lot
|
|
|
|
#
|
|
|
|
|
2020-08-10 01:44:11 -05:00
|
|
|
which awk >/dev/null && AWK=awk
|
|
|
|
which gawk >/dev/null && AWK=gawk
|
|
|
|
|
2017-07-27 03:02:53 -05:00
|
|
|
KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2"
|
2017-05-05 00:46:39 -05:00
|
|
|
|
2017-04-20 21:10:41 -05:00
|
|
|
echo "Fetching latest upstream and origin..."
|
|
|
|
git fetch upstream
|
|
|
|
git fetch origin
|
|
|
|
echo
|
|
|
|
|
2016-04-18 23:18:35 -05:00
|
|
|
echo "Pruning Merged Branches..."
|
2017-05-05 00:46:39 -05:00
|
|
|
git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
|
2016-04-18 23:18:35 -05:00
|
|
|
echo
|
|
|
|
|
|
|
|
echo "Pruning Remotely-deleted Branches..."
|
2020-08-10 01:44:11 -05:00
|
|
|
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | "$AWK" '{print $1}' | xargs -n 1 git branch -D
|
2016-04-18 23:18:35 -05:00
|
|
|
echo
|
|
|
|
|
2017-07-02 20:43:57 -05:00
|
|
|
# List fork branches that don't match local branches
|
2017-04-20 21:10:41 -05:00
|
|
|
echo "You may want to remove (or checkout) these refs..."
|
2016-04-18 23:18:35 -05: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-07-02 20:43:57 -05:00
|
|
|
| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; print ""; }'
|
2016-04-18 23:18:35 -05:00
|
|
|
echo
|