From 5e0bc944655806c3f2afcc40c1a27cc476453fb7 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Wed, 31 Jan 2018 09:34:45 -0700 Subject: [PATCH] Update git-cleanup to be smarter and more informative * Refresh local state before doing any work * Only delete branches which have been merged back to master * List branches deleted and branches remaining --- home/bin/git-cleanup | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/home/bin/git-cleanup b/home/bin/git-cleanup index d0f3f47..3353770 100755 --- a/home/bin/git-cleanup +++ b/home/bin/git-cleanup @@ -1,3 +1,17 @@ #!/usr/bin/env bash -git branch | grep -v master | grep -v '\*' | while read BRANCH; do git branch -d $BRANCH -q; done +git checkout master +git pull + +DELETED="0" +git branch --merged master | grep -v master | while read BRANCH; do + git branch -d $BRANCH + (( DELETED = DELETED + 1 )) +done + +if [[ "$DELETED" -eq "0" ]]; then + echo "No branches to clean up." +fi + +echo "Branches remaining:" +git branch