Last active
April 27, 2021 17:40
-
-
Save vipyne/2f27ff38f27f60c0f6ac323fcf0658db to your computer and use it in GitHub Desktop.
Iterate through local git branches and choose whether or not to delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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