Skip to content

Instantly share code, notes, and snippets.

@vipyne
Last active April 27, 2021 17:40
Show Gist options
  • Save vipyne/2f27ff38f27f60c0f6ac323fcf0658db to your computer and use it in GitHub Desktop.
Save vipyne/2f27ff38f27f60c0f6ac323fcf0658db to your computer and use it in GitHub Desktop.
Iterate through local git branches and choose whether or not to delete
#! /usr/bin/env bash
echo "*** CLEAN UP BRANCHES ***"
echo
git branch
echo
branches=$(git branch)
IFS="
"
for b in $branches; do
if [[ "$b" =~ "main" ]];then continue;fi
echo -n "Delete$b (y/n)? "
read answer
if [ "$answer" != "${answer#[yY]}" ]; then
git branch -D "$(echo -n "${b//[[:space:]]/}")"
echo
elif [ "$answer" != "${answer#[qQ]}" ]; then
git branch
echo
exit 0
else
echo
fi
done
git branch
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment