Thursday, February 10, 2011

Making a New Remote Branch with Git

This works for me at work.  I can't guarantee it'll work for anybody who doesn't work with me.  We'll be creating a new branch called "new-feature."

First checkout the branch you want to branch from.
$ git checkout master

Make sure ever thing is updated (fix any problems that might happen here).
$ git pull

Check you are in the right branch (note the asterisks).
$ git branch
* master
  staging
Create new local branch
$ git branch new-feature

Checkout the new branch
$ git checkout new-feature

Double check you are in the right branch and the remote branches are good
$ git branch -a
* new-feature
  master
  staging
  origin/HEAD
  origin/master
  origin/staging
Push local branch to create remote branch
$ git push origin new-feature

Triple check your branches to make sure everything shows up as expected.
$ git branch -a
* new-feature
  master
  staging
  origin/HEAD
  origin/master
  origin/new-feature
  origin/staging

Other developers who might also want to use the new branch can now easily do so.  If they do git branch -a the new branch will show up on the list as a remote branch.  If they want to actively work with the branch they need to check it out to their local machine.
$ git checkout -tb new-feature origin/new-feature