This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/buildroot/share/git/mfclean

30 lines
945 B
Text
Raw Normal View History

#!/usr/bin/env bash
#
2017-05-05 07:46:39 +02: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
#
2017-05-05 07:46:39 +02:00
KEEP="RC|RCBugFix|dev|master|bugfix-1"
echo "Fetching latest upstream and origin..."
git fetch upstream
git fetch origin
echo
echo "Pruning Merged Branches..."
2017-05-05 07:46:39 +02:00
git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
echo
echo "Pruning Remotely-deleted Branches..."
2017-05-05 07:46:39 +02:00
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
echo
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; }'
echo