Created
January 15, 2010 00:08
-
-
Save IcyMidnight/277643 to your computer and use it in GitHub Desktop.
Bash function to create a new git remote branch, a new local branch to track it, and then start using that branch
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 | |
function git-create-branch() { | |
if [ $# -ne 1 ]; then | |
echo 1>&2 Usage: $0 branch_name | |
exit 127 | |
fi | |
branch_name=$1 | |
# Create the remote branch | |
echo "git push origin master:refs/heads/$branch_name" | |
git push origin master:refs/heads/$branch_name | |
# Make sure the local repo is up to date | |
git fetch origin | |
# Create the new local branch, have it track the remote branch, and switch to the new branch | |
git checkout --track -b $branch_name origin/$branch_name | |
# Make sure things are up to date again | |
git pull | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment