Monday, February 1, 2010

Git branch naming

I have a git project that I've been working on for a while. One of the devs branched it and I need to work on both branches. So now I need to have the two branches - master and 2-0-stable - on my local repository. Simple:

Make sure I'm up to date
git pull

Get a local copy of the new branch
git checkout --track -b stable origin/stable

Confirm I can push and pull to both branches
git remote show origin

Which shows this:
penitentes:csh_home cpowell (2-0-stable)$ git remote show origin
* remote origin
Fetch URL:
Push URL:
HEAD branch: master
Remote branches:
2-0-stable tracked
master tracked
Local branches configured for 'git pull':
2-0-stable merges with remote 2-0-stable
master merges with remote master
Local refs configured for 'git push':
2-0-stable pushes to 2-0-stable (up to date)
master pushes to master (up to date)

And then I can switch between branches with:
git checkout [my branch name]

There are two gotchas that I ran into:
  1. If you don't give your local branch the same name as the remote branch, you won't be able to push.
  2. When you pull the new branch, your changes will go on the new branch as well.

No comments:

Post a Comment