diff options
author | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
---|---|---|
committer | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
commit | e8701195e66f2d27ffe17fb514eae8173795aaf7 (patch) | |
tree | 9f519c4abf6556b9ae7190a6210d87ead1dfadde /buildroot/share/git/mfclean | |
download | kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip |
Initial commit
Diffstat (limited to 'buildroot/share/git/mfclean')
-rw-r--r-- | buildroot/share/git/mfclean | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/buildroot/share/git/mfclean b/buildroot/share/git/mfclean new file mode 100644 index 0000000..fd131c4 --- /dev/null +++ b/buildroot/share/git/mfclean @@ -0,0 +1,32 @@ +#!/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 +# + +AWK=$(which gawk || which awk) + +KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2" + +echo "Fetching latest upstream and origin..." +git fetch upstream +git fetch origin +echo + +echo "Pruning Merged Branches..." +git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d +echo + +echo "Pruning Remotely-deleted Branches..." +git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | "$AWK" '{print $1}' | xargs -n 1 git branch -D +echo + +# List fork branches that don't match local branches +echo "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 |