Skip to content

Instantly share code, notes, and snippets.

@robertoestivill
Created July 17, 2017 11:15
Show Gist options
  • Save robertoestivill/194fb4f9def228edb4f4f9a6709fc188 to your computer and use it in GitHub Desktop.
Save robertoestivill/194fb4f9def228edb4f4f9a6709fc188 to your computer and use it in GitHub Desktop.
Iterate over local git branches and prompt the user for deletion confirmation.
#!/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