Skip to content

Instantly share code, notes, and snippets.

@gleuch
Created February 16, 2011 22:36
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 gleuch/830432 to your computer and use it in GitHub Desktop.
Save gleuch/830432 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# branch [branchname]
#
# Create a new local AND remote git branch
# Setup local branch to use remote tracking
#
branch=$1
if [ -z $branch ]; then
git branch
else
echo branch: $branch
# You were probably on master, but just in case...
old_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
remote=origin
# I've run into issues using the "correct" create-remote-from-local-with-tracking flow,
# so let's just be explicit about it. Create local, push it, delete it, recreate w/ tracking
git checkout -b $branch
git push $remote $branch
git checkout $old_branch
git branch -D $branch
git checkout -b $branch --track $remote/$branch
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment