1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 22:08:02 +00:00
MarlinFirmware/buildroot/share/git/mfclean

33 lines
1.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
2017-05-05 05:46:39 +00:00
# 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
#
2020-08-11 01:03:13 +00:00
AWK=$(which gawk || which awk)
2020-08-10 06:44:11 +00:00
2017-07-27 08:02:53 +00:00
KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2"
2017-05-05 05:46:39 +00:00
echo "Fetching latest upstream and origin..."
git fetch upstream
git fetch origin
echo
echo "Pruning Merged Branches..."
2017-05-05 05:46:39 +00:00
git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
echo
echo "Pruning Remotely-deleted Branches..."
2020-08-10 06:44:11 +00:00
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | "$AWK" '{print $1}' | xargs -n 1 git branch -D
echo
2017-07-03 01:43:57 +00:00
# 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; }') \
2017-07-03 01:43:57 +00:00
| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; print ""; }'
echo