Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Last active June 22, 2020 17:57
Show Gist options
  • Save jaredbeck/66f4e18d0d8834c508e35d6f77206be9 to your computer and use it in GitHub Desktop.
Save jaredbeck/66f4e18d0d8834c508e35d6f77206be9 to your computer and use it in GitHub Desktop.
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