Last active
December 22, 2015 11:38
-
-
Save tupakapoor/69b262b8f3245df3db5f to your computer and use it in GitHub Desktop.
A script to make creating a new branch from the most up to date version of upstream/master easier
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 [ -z "$1" ]; then | |
echo usage: newbranch newbranchname oldbranchtoclonefrom | |
exit | |
fi | |
git remote -v | grep upstream > /dev/null | |
if [ $? -ne 0 ]; then | |
echo You must have a remote named upstream | |
exit | |
fi | |
if [ -n "$2" ]; then | |
git checkout $2 | |
else | |
git checkout master | |
fi | |
if [ $? -ne 0 ]; then | |
exit | |
fi | |
git fetch upstream | |
if [ -n "$2" ]; then | |
git merge upstream/$2 | |
else | |
git merge upstream/master | |
fi | |
if [ $? -ne 0 ]; then | |
exit | |
fi | |
git checkout -b $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was looking forever for this, but I as well got a little lazy
alias branch=branch
branch() {
git fetch --all
if [ -z "$2" ]; then
git checkout -b $1 upstream/master
else
git checkout -b $1 upstream/$2
fi
}