Skip to content

Instantly share code, notes, and snippets.

@tomaszprasolek
Last active March 27, 2019 13:24
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 tomaszprasolek/e3efa6126888ccd387f03512b3ac8153 to your computer and use it in GitHub Desktop.
Save tomaszprasolek/e3efa6126888ccd387f03512b3ac8153 to your computer and use it in GitHub Desktop.
Script create local branch and after that set upstream branch
#!/bin/bash
if [ x = x${1} ]; then
echo ">>> Enter branch name"
exit 1
fi
if [[ $1 == feature* ]]
then
BRANCH_NAME=$1
else
BRANCH_NAME="feature/$1"
fi
RESULT=$(git rev-parse --verify --quiet $BRANCH_NAME) # https://gist.github.com/tennisonchan/e00212e3ed5498060c50d390233a3e1f
if [ ! -z "$RESULT" ] # https://serverfault.com/questions/7503/how-to-determine-if-a-bash-variable-is-empty
then
echo "Branch named \"$BRANCH_NAME\" already exists."
exit 1
fi
git checkout -b $BRANCH_NAME
git push -u origin $BRANCH_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment