You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
945 B
30 lines
945 B
9 years ago
|
#!/usr/bin/env bash
|
||
|
#
|
||
8 years ago
|
# mfclean
|
||
9 years ago
|
#
|
||
|
# Prune all your merged branches and any branches whose remotes are gone
|
||
|
# Great way to clean up your branches after messing around a lot
|
||
|
#
|
||
|
|
||
8 years ago
|
KEEP="RC|RCBugFix|dev|master|bugfix-1"
|
||
|
|
||
8 years ago
|
echo "Fetching latest upstream and origin..."
|
||
|
git fetch upstream
|
||
|
git fetch origin
|
||
|
echo
|
||
|
|
||
9 years ago
|
echo "Pruning Merged Branches..."
|
||
8 years ago
|
git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
|
||
9 years ago
|
echo
|
||
|
|
||
|
echo "Pruning Remotely-deleted Branches..."
|
||
8 years ago
|
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
|
||
9 years ago
|
echo
|
||
|
|
||
8 years ago
|
echo "You may want to remove (or checkout) these refs..."
|
||
9 years ago
|
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; }') \
|
||
8 years ago
|
| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; }'
|
||
9 years ago
|
echo
|