Skip to content

Instantly share code, notes, and snippets.

@donmccurdy
Last active September 1, 2023 15:11
Show Gist options
  • Save donmccurdy/67004e5fcf520cf94f934c9459a04e2c to your computer and use it in GitHub Desktop.
Save donmccurdy/67004e5fcf520cf94f934c9459a04e2c to your computer and use it in GitHub Desktop.
Clean up old Git branches.
#! /bin/bash
echo "Cleaning up git branches..."
git branch --format="%(refname:short)" | grep -v -E "master|dev" | while read branchname; do
read -n 1 -p $'\nDelete branch '"$branchname"$'? (Yn)\n' yn </dev/tty
case ${yn:0:1} in
y|Y )
git branch -D $branchname
;;
* )
echo "Skipping"
;;
esac
done
echo "...done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment