Skip to content

Instantly share code, notes, and snippets.

@tupakapoor
Last active December 22, 2015 11:38
Show Gist options
  • Save tupakapoor/69b262b8f3245df3db5f to your computer and use it in GitHub Desktop.
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
#!/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
@TeddyRux
Copy link

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
}

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