63

I read some information about named branches and working with bookmarks. Unfortunately I still don't see a difference between them. Is there any?

Is there any difference between:

hg branch blah
hg up blah

and

hg bookmark blah
hg up blah

?

Why would I use a bookmark and how is it different from a named branch?

viraptor
  • 33,322
  • 10
  • 107
  • 191
  • 1
    As a side note: You can apply a bookmark to a branch *after* you started working on the branch. This may be helpful if you've developed something, but then have to go back to an older revision and start developing something unrelated (e.g. because your team leader told you so). In this case, you can bookmark the first branch with some meaningful name. – Sebastian Krysmanski Feb 24 '15 at 11:05

1 Answers1

61

Bookmarks are tags that move forward automatically to subsequent changes, leaving no mark on the changesets that previously had that bookmark pointing toward them. Named branches, on the other hand, are indelible marks that are part of a changeset. Multiple heads can be on the same branch, but only one head at a time can be pointed to by the same bookmark. Named branches are pushed/pulled from repo to repo, and bookmarks don't travel.

There's a great branching comparison here: http://stevelosh.com/blog/entry/2009/8/30/a-guide-to-branching-in-mercurial/

Michael
  • 8,920
  • 3
  • 38
  • 56
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 28
    1. Article was updated: "As of Mercurial 1.6 bookmarks can be pushed and pulled between repositories." 2. This explains the differences, but not why you would want to use one over the other – Casebash Sep 09 '10 at 12:08
  • 3
    The differences should help you pick which model works best for you, and each has clear tradeoffs. Do you want your branch names to stay around forever? Use named branches. Etc. – Ry4an Brase Sep 09 '10 at 14:20
  • 8
    the mercurial wiki says that named branches is for "long living branches of development". So, I would create branch for new-major-release, but use bookmarks for fix-bug-XXX branch. – Vadim Fint Dec 19 '10 at 13:41
  • "only one head at a time can be pointed to by the same bookmark" AFAIK this is not true - you can have as many bookmarks as you like on any commit, head or not. However only one bookmark can be -active- at a time (i.e. committing will automatically advance that bookmark). – Dan Passaro Apr 28 '15 at 14:04
  • 2
    @DanPassaro: I think you read that sentence the wrong way round. It's saying no single bookmark can point to more than one commit at once (which seems perfectly obvious to me but might not be obvious to someone with less Mercurial experience). – Kevin Apr 05 '17 at 21:42
  • @Kevin Yes, you are correct. I can't remember what idea I had in my head when I made that comment. The reference to active bookmarks also seems to be totally irrelevant and makes little sense to me. Hopefully I was drunk at the time. – Dan Passaro Apr 06 '17 at 15:08