Tuesday, March 31, 2009

Mercurial Branching

It's easy to do local branching in mercurial. My partner was exploring it for the first time and asked if this was supported in mercurial since it was supported in git. I didn't know, and dug into the the Mercurial book (pdf book) to find the answer. It's really very easy, though the use of update is a little odd.

You only really need the update and branch commands, but I include others here because they provide aid and comfort.

hg branch Name creates branch Name, and it becomes active on the next commit.
hg branch shows the current branch (no param).
hg branches shows the local branches.
hg update Name switches to the branch called Name.
hg tip shows you where you are wrt: branches, etc.
hg merge Name merges the named branch with the current one.

When you do a commit and allow mercurial to call up the editor, the commit message will be populated with the tip information, so you know for sure which branch you are in.

WAIT! these branches are not what you think they are. They are (as darrint said) permanent, and you can't really push to (or pull from) a separate repo into a temp branch. It's a very different concept from svn switch.

So be careful with that axe eugene.

1 comment:

  1. If you are coming from git you might find the "hg bookmark" feature more helpful.

    Git branches can be ephemeral. Hg branches are usually permanent.

    ReplyDelete