Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Loop over git branches, interactively inspecting/deleting them
#!/usr/bin/env bash
set -e
for BRANCH in $(git branch --format '%(refname:short)' | egrep -v '(master|dev)')
do
NEXT_BRANCH=false
until [ "$NEXT_BRANCH" = true ]
do
echo -e "\n$BRANCH"
git show "$BRANCH" | egrep '^Date:'
git diff --shortstat "$BRANCH"
echo "(d = delete, f = diff --stat, s = skip, q = quit)"
read CMD
case $CMD in
'd')
git branch -D "$BRANCH"
NEXT_BRANCH=true
;;
'f')
git diff --stat "$BRANCH"
;;
's')
echo 'Skipped'
NEXT_BRANCH=true
;;
'q')
exit 0
;;
*)
esac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment