Last active
August 12, 2019 19:44
-
-
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
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thanmaster