Last active
March 27, 2019 13:24
-
-
Save tomaszprasolek/e3efa6126888ccd387f03512b3ac8153 to your computer and use it in GitHub Desktop.
Script create local branch and after that set upstream branch
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 | |
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