Skip to content

Instantly share code, notes, and snippets.

@mosheeshel
Last active August 12, 2019 19:44
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 mosheeshel/b1317e32ed33b0205be9ec4b6d79f804 to your computer and use it in GitHub Desktop.
Save mosheeshel/b1317e32ed33b0205be9ec4b6d79f804 to your computer and use it in GitHub Desktop.
Quick bash script to start a new GIT branch from master or from any other existing branch
create_branch() {
local ORIGIN_BRANCH="origin/master"
if [ -z "$1" ] ; then
echo "branch name is required"
else
if [ ! -z "$2" ] ; then
local ORIGIN_BRANCH="$2"
fi
git checkout -b $1 $ORIGIN_BRANCH
git push -u origin $1:$1
fi
}
alias branch=create_branch
@mosheeshel
Copy link
Author

You can put this in you .bash file (or .zsh in my case).
this allows you from your shell (inside your git repo directory) to call
branch <name>
this creates a local branch that is already tracking a remote branch so that git push has a target.
another variation is branch <name> <remote> in which it will create a new branch based on a remote branch other than master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment