Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created July 12, 2011 18:32
Show Gist options
  • Save slackorama/1078627 to your computer and use it in GitHub Desktop.
Save slackorama/1078627 to your computer and use it in GitHub Desktop.
#!/bin/bash
# hack -- create a branch for a bz ticket off of whatever branch you are
# currently in or the branch you pass in as an argument
bug=$1
base=$2
if [ -z "${bug}" ] || [ "${bug}" == "-?" ] ; then
echo "Usage: hack [BZTICKET]"
exit 1
fi
if ! echo $bug | egrep -q "^bugfix/bz" ; then
bug=bugfix/bz${bug}
fi
if [ -z "$base" ]; then
current=`git branch | awk '/\*/{print $2}'`
remote=`git config --get branch.$current.remote`
git fetch -q $remote
git checkout -b ${bug} $remote/$current
else
remote=`git config --get branch.$base.remote`
if [ -z "$remote" ]; then
echo "No remote found for $base" >&2;
exit 1;
fi
git remote update $remote
git checkout -b ${bug} $remote/$base
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment