views:

550

answers:

2

I am not having any luck using Bookmarks in Mercurial for Git like branching.

From the article: http://mercurial.selenic.com/wiki/BookmarksExtension, I've set "track.current" to true in my .hgrc file.

Excerpt below:

By default, when several bookmarks point to the same changeset, they will all move forward together. It is possible to obtain a more Git-like experience by adding the following configuration option to your .hgrc

[bookmarks]
track.current = True

However, as soon as I start trying to do parallel / independent development on more than one bookmark, then switch back and forth between the bookmarks, I run into the following:

abort: crosses branches (use 'hg merge' or 'hg update -C')

Example to reproduce:

# Make a new directory and Mercurial repository
$ mkdir bookmark
$ cd bookmark
$ hg init

# Create two bookmarks
$ hg bookmark bk1
$ hg bookmark bk2

# Checkout bk1
$ hg update bk1
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

# Create and commit a file to bk1
$ touch bk1.txt
$ hg add
adding bk1.txt
$ hg commit -m "bk1 file"

# Checkout bk2
$ hg update bk2
0 files updated, 0 files merged, 1 files removed, 0 files unresolved

# Create and commit a file to bk2
$ touch bk2.txt
$ hg add
adding bk2.txt
$ hg commit -m "bk2 file"
created new head

# Checkout bk1
$ hg up bk1
abort: crosses branches (use 'hg merge' or 'hg update -C')

Is this normal behavior, for there to be "crosses branches" forcing a merge or file overwrite, when moving between bookmarks?

For a 'Git-like experience' I would expect to be able to flick back and forth between bk1 and bk2, committing and developing on either, merging if and when I needed to.

+9  A: 

Please upgrade to Mercurial 1.4, which was released last week. Then you will be able to switch between heads on a branch without warning.

Martin Geisler
Updated to Mercurial 1.4 and can confirm that it gives bookmarks git like branching behavior without the abort / warnings. Thanks.
buymeasoda
buymeasoda: thanks a lot for reporting back! PS: I like your username :-)
Martin Geisler
Furthermore, upgrade to version 1.6 (to be released in two weeks) to get bookmarks that you an push/pull between repositories.
Martin Geisler
+2  A: 

Using a Mercurial version earlier than 1.4, you can just provide the -c flag, as long as your working tree is clean (no uncommitted changes).

Carl Meyer