Created
February 16, 2011 22:36
-
-
Save gleuch/830432 to your computer and use it in GitHub Desktop.
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/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