# coming from git, understanding mercurial branching

7 messages from 2013-09-06 to 2013-09-08. Participants: Tim Chase, Tay Ray Chuan, Konstantin Khomoutov, Philip Oakley, Felipe Contreras.
Thread: https://gitlist.dev/t/34860

## Tim Chase, 2013-09-06 02:27

Subject: coming from git, understanding mercurial branching
Message-ID: <20130905212714.636db4c4@bigbox.christie.dr>
URL: https://gitlist.dev/e/20130905212714.636db4c4%40bigbox.christie.dr

```
I've got a pretty good grasp on git's rather straightforward
branching, but am trying to wrap my head around Mercurial's
branching.  There seem to be several flavors, some default to
push-public, while others are private; some are tracked in history,
while others seem more ephemeral; often the docs suggest cloning
instead of branching; detached heads seem more normal in the
Mercurial world.

Do any git users here have good "understanding Mercurial branches
for the git user" resources they've found helpful when working with
Mercurial?  Preferably a "for dummies" resource with illustrations &
comparison charts so I can see the big picture.

Thanks

-tkc


PS: I've read a couple Mercurial resources including
http://mercurial.selenic.com/wiki/GitConcepts
but it didn't really dig into comparing the mental models used in
branching.  

```

## Tay Ray Chuan, 2013-09-06 04:39

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <CALUzUxoa7Lw-_sj3LRj-9=hSh17hi+j4JhfAPKaDfhuE8PnKCA@mail.gmail.com>
URL: https://gitlist.dev/e/CALUzUxoa7Lw-_sj3LRj-9%3DhSh17hi%2Bj4JhfAPKaDfhuE8PnKCA%40mail.gmail.com
In-Reply-To: <20130905212714.636db4c4@bigbox.christie.dr>

```
On Fri, Sep 6, 2013 at 10:27 AM, Tim Chase <git@tim.thechases.com> wrote:
> I've got a pretty good grasp on git's rather straightforward
> branching, but am trying to wrap my head around Mercurial's
> branching.  There seem to be several flavors, some default to
> push-public, while others are private; some are tracked in history,
> while others seem more ephemeral;

First: recognize Mercurial's branches are entirely different beasts
from Git's. They just happen to be given a same sequence of
characters, b-r-a-n-c-h. The similarities end there!

> often the docs suggest cloning
> instead of branching; detached heads seem more normal in the
> Mercurial world.

Are you referring to this?

  $ hg clone https://... master
  $ cd master
  # hack...

  $ cd ..
  $ hg clone https://... fix1
  $ cd fix1
  # hack...

  $ cd../master
  $ hg pull ../fix1
  $ hg merge ...

In git, you would have your master branch, checkout -b fix1, then
merge them back to master when you're done. The above describes how
one would do this in mercurial.

-- 
Cheers,
Ray Chuan

```

## Tim Chase, 2013-09-06 13:26

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <20130906082621.01162905@bigbox.christie.dr>
URL: https://gitlist.dev/e/20130906082621.01162905%40bigbox.christie.dr
In-Reply-To: <CALUzUxoa7Lw-_sj3LRj-9=hSh17hi+j4JhfAPKaDfhuE8PnKCA@mail.gmail.com>

```
On 2013-09-06 12:39, Tay Ray Chuan wrote:
> First: recognize Mercurial's branches are entirely different beasts
> from Git's. They just happen to be given a same sequence of
> characters, b-r-a-n-c-h. The similarities end there!

Yeah, I'm trying to create a mental map between what Git means by
branching, and what Mercurial means by branching.  As you say, they
seem to be entirely different beasts.

> > often the docs suggest cloning instead of branching;
> 
> Are you referring to this?
> 
>   $ hg clone https://... master
>   $ cd master
>   # hack...
> 
>   $ cd ..
>   $ hg clone https://... fix1

Usually I see this written as

  $ cd ..
  $ hg clone master fix1

but otherwise, yes.

>   $ cd fix1
>   # hack...
> 
>   $ cd../master
>   $ hg pull ../fix1
>   $ hg merge ...
> 
> In git, you would have your master branch, checkout -b fix1, then
> merge them back to master when you're done. The above describes how
> one would do this in mercurial.

Mercurial has this cloning-branch thing, a "branch" command, and
something called "bookmarks" which all seem to have different
behaviors (and corresponding reasons to choose them) and yet all be
loosely referred to as "branching".  Cloning litters the drive with
duplicate checkouts (even if they use hard-linking for the repo
behind the scenes, there's still a lot of time spent writing.  The
git equiv of this hg suite would be almost identical, cloning a
local checkout); the 2nd and 3rd are more branch-related and what I'm
trying to grok.

-tkc

```

## Konstantin Khomoutov, 2013-09-06 13:51

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <20130906175124.7d08947410503681449642ad@domain007.com>
URL: https://gitlist.dev/e/20130906175124.7d08947410503681449642ad%40domain007.com
In-Reply-To: <20130905212714.636db4c4@bigbox.christie.dr>

```
On Thu, 5 Sep 2013 21:27:14 -0500
Tim Chase <git@tim.thechases.com> wrote:

[...]
> Do any git users here have good "understanding Mercurial branches
> for the git user" resources they've found helpful when working with
> Mercurial?  Preferably a "for dummies" resource with illustrations &
> comparison charts so I can see the big picture.

I found this guide [1] very useful back in the time I tried to grok
Mercurial.

1. http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

```

## Philip Oakley, 2013-09-06 16:40

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <E27274C44BAD4DAE92D9D89AA9591CEF@PhilipOakley>
URL: https://gitlist.dev/e/E27274C44BAD4DAE92D9D89AA9591CEF%40PhilipOakley
In-Reply-To: <20130906175124.7d08947410503681449642ad@domain007.com>

```
From: "Konstantin Khomoutov" <flatworm@users.sourceforge.net>
To: "Tim Chase" <git@tim.thechases.com>
> On Thu, 5 Sep 2013 21:27:14 -0500
> Tim Chase <git@tim.thechases.com> wrote:
>
> [...]
>> Do any git users here have good "understanding Mercurial branches
>> for the git user" resources they've found helpful when working with
>> Mercurial?  Preferably a "for dummies" resource with illustrations &
>> comparison charts so I can see the big picture.
>
> I found this guide [1] very useful back in the time I tried to grok
> Mercurial.
>
> 1. 
> http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/
> --
Tim,
Another recent blog is 
http://felipec.org/2013/08/27/analysis-of-hg-and-git-branches/ by Felipe 
Contreras who wrote Git's official GitMercurial bridge; git-remote-hg

Philip 

```

## Tim Chase, 2013-09-06 19:29

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <20130906142927.279a994a@bigbox.christie.dr>
URL: https://gitlist.dev/e/20130906142927.279a994a%40bigbox.christie.dr
In-Reply-To: <20130906175124.7d08947410503681449642ad@domain007.com>

```
On 2013-09-06 17:51, Konstantin Khomoutov wrote:
> I found this guide [1] very useful back in the time I tried to grok
> Mercurial.
> 
> 1.
> http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

Indeed, after reading it, that's the most sense I've been able to make
of Mercurial's strange branching.  I guess it boils down to the
following rough heuristic:

- if you want to dink around locally, but don't want to publish your
  branches (yet), default to bookmarks using "hg bookmark"

- once you want a branch to be public, consider making a "real"
  branch using "hg branch"

- if you want complete isolation in case you screw up something like
  merging, use a clone


I still prefer Git's way, but at least I'm not left scratching my
head when I have to play with Mercurial branches.

Thanks, all.

-tkc

```

## Felipe Contreras, 2013-09-08 00:42

Subject: Re: coming from git, understanding mercurial branching
Message-ID: <CAMP44s3ypvEBWnsfN5c73wT8cvGhpTnd3vbmpPfn8GMb4FVLvQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s3ypvEBWnsfN5c73wT8cvGhpTnd3vbmpPfn8GMb4FVLvQ%40mail.gmail.com
In-Reply-To: <20130906142927.279a994a@bigbox.christie.dr>

```
On Fri, Sep 6, 2013 at 2:29 PM, Tim Chase <git@tim.thechases.com> wrote:
> On 2013-09-06 17:51, Konstantin Khomoutov wrote:
>> I found this guide [1] very useful back in the time I tried to grok
>> Mercurial.
>>
>> 1.
>> http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

I've written various blog posts about the subject:

http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/
http://felipec.wordpress.com/2012/05/26/no-mercurial-branches-are-still-not-better-than-git-ones-response-to-jhws-more-on-mercurial-vs-git-with-graphs/
http://felipec.wordpress.com/2013/08/27/analysis-of-hg-and-git-branches/

> Indeed, after reading it, that's the most sense I've been able to make
> of Mercurial's strange branching.  I guess it boils down to the
> following rough heuristic:
>
> - if you want to dink around locally, but don't want to publish your
>   branches (yet), default to bookmarks using "hg bookmark"

Kind of, but then they added support to push bookmarks, so now you can
fetch and push them, so not exactly local.

In addition, they are starting to think on adding remote namespaces,
like in Git, except that jon/devel becomes jon@devel.

> - once you want a branch to be public, consider making a "real"
>   branch using "hg branch"

Not necessarily. You can merge or rebase, so "the public" doesn't see
the bookmark.

> - if you want complete isolation in case you screw up something like
>   merging, use a clone

I guess so. There's also the option of using the 'mq' extension, which
I guess it's similar to quilt.

-- 
Felipe Contreras

```
