Skip to content

Instantly share code, notes, and snippets.

@rjocoleman
Created March 18, 2014 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjocoleman/9631735 to your computer and use it in GitHub Desktop.
Save rjocoleman/9631735 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Aliased as $ git c
# $ git config --global alias.c qa-checkout
# checks to see if checkout -b is happening
# if it is and it fails because the branch already exists
# prompt to delete the existing branch
if [[ $1 == '-b' ]]
then
git checkout $@
status=$?
if [ $status -eq 128 ]; then
while true; do
read -p "Do you want to delete the branch $2? " yn
case $yn in
[Yy]* ) git branch -D $2 && git checkout $@; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
else
git checkout $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment