threads / discuss / 34860

coming from git, understanding mercurial branching

Subject: coming from git, understanding mercurial branching

## tl;dr

7 messages between Sep 6, 2013 and Sep 8, 2013.

replies: 6people: 5as markdown or json

Tim Chase· Sep 6, 2013, 02:27 UTC · lore

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· Sep 6, 2013, 04:39 UTC · re: Tim Chase · lore

Re: coming from git, understanding mercurial branching

On Fri, Sep 6, 2013 at 10:27 AM, Tim Chase <git@tim.thechases.com> wrote:
Show 5 quoted lines
> 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· Sep 6, 2013, 13:26 UTC · re: Tay Ray Chuan · lore

Re: coming from git, understanding mercurial branching

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.

Show 10 quoted lines
> > 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.
Show 10 quoted lines
>   $ 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· Sep 6, 2013, 13:51 UTC · re: Tim Chase · lore

Re: coming from git, understanding mercurial branching

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· Sep 6, 2013, 16:40 UTC · re: Konstantin Khomoutov · lore

Re: coming from git, understanding mercurial branching

From: "Konstantin Khomoutov" <flatworm@users.sourceforge.net>
To: "Tim Chase" <git@tim.thechases.com>
Show 15 quoted lines
> 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· Sep 6, 2013, 19:29 UTC · re: Konstantin Khomoutov · lore

Re: coming from git, understanding mercurial branching

On 2013-09-06 17:51, Konstantin Khomoutov wrote:
Show 5 quoted lines
> 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· Sep 8, 2013, 00:42 UTC · re: Tim Chase · lore

Re: coming from git, understanding mercurial branching

On Fri, Sep 6, 2013 at 2:29 PM, Tim Chase <git@tim.thechases.com> wrote:
Show 6 quoted lines
> 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/

Show 6 quoted lines
> 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

← back to recent threads