Skip to content

Instantly share code, notes, and snippets.

@IcyMidnight
Created January 15, 2010 00:08
Show Gist options
  • Save IcyMidnight/277643 to your computer and use it in GitHub Desktop.
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
#!/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