Created
May 25, 2016 18:14
-
-
Save lorenmh/85745aadad75b1e10bdb388026618edd to your computer and use it in GitHub Desktop.
clean branches from current git directory
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
#!/bin/bash | |
# Loren - 2/12/16 | |
# you can provide some grep regex as the first arg if you want to delete only | |
# specific branches | |
if [ $1 ] | |
then | |
branches="git branch | sed 's/^\*//' | grep $1" | |
else | |
branches="git branch | sed 's/^\*//'" | |
fi | |
for branch in $(eval $branches) | |
do | |
have_user_input=0 | |
should_delete=0 | |
while ! (( $have_user_input )) | |
do | |
echo Delete branch $branch? [ynq] | |
read answer | |
if [ "$answer" == "y" ] || [ "$answer" == "yes" ] | |
then | |
should_delete=1 | |
have_user_input=1 | |
elif [ "$answer" == "n" ] || [ "$answer" == "no" ] | |
then | |
should_delete=0 | |
have_user_input=1 | |
elif [ "$answer" == "q" ] || [ "$answer" == "quit" ] || [ "$answer" == "exit" ] | |
then | |
echo Exiting | |
exit | |
else | |
echo 'Invalid input, enter y or n or q' | |
fi | |
done | |
if [ $should_delete -eq 1 ] | |
then | |
git branch -D $branch | |
else | |
echo Not deleting branch $branch. | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment