Created
July 17, 2017 11:15
-
-
Save robertoestivill/194fb4f9def228edb4f4f9a6709fc188 to your computer and use it in GitHub Desktop.
Iterate over local git branches and prompt the user for deletion confirmation.
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 | |
CURRENT=$(git branch | grep "*" | cut -c3-) | |
printf "Your current branch is '$CURRENT'. Will be ignored.\n\n" | |
BRANCHES=$(git branch | cut -c3-) | |
BRANCHES=${BRANCHES[@]/$CURRENT} | |
for BRANCH in ${BRANCHES} | |
do | |
read -r -p "Delete '${BRANCH}' ? " CONFIRMATION | |
case "$CONFIRMATION" in | |
[yY][eE][sS]|[yY]) | |
git branch -D $BRANCH | |
;; | |
*) | |
printf "No\n" | |
;; | |
esac | |
printf "\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment