Rook
Rook

Reputation: 62528

Can I branch in Mercurial without cloning the repository?

Recently, I've started experimenting with Mercurial, due to the fact that it always attracted it because of its simplicity and "just works" principle. Or at least, that's how others always described it.

They also usually described it as "practically the same as git with just a few minor changes you won't notice" - only for me to discover it isn't quite so.

I'm having problem with Hg branches. Pardon me if this is an overly simple question, but in git one has a working directory and a repo (.git). In the repo one has revisions, and branches, and can jump from one to another.

I'm having trouble finding a similar model in Hg. As far as I can see, for Hg to have a "branch" one needs to clone a repo to another directory? Is there a way Hg could work just like git does - i.e. one working dir., and one repo, in which you can do things as regard to branching and revs?

Upvotes: 3

Views: 473

Answers (3)

Jakub Narębski
Jakub Narębski

Reputation: 323354

Take a look at section about branches in my answer to "Git and Mercurial - Compare and Contrast" here on StackOverflow.

The information about various options available for branching in Mercurial (anonymous heads, not-propagated (I think yet still) bookmarks, and global (world-wide) commit labels aka named branches) was taken from http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/, and expanded using feedback on #mercurial IRC channel on FreeNode.

Upvotes: 2

Matthew Manela
Matthew Manela

Reputation: 16752

Mercurial supports a very rich set of ways to branch. See http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

In brief, you can create a named branch by running

hg branch NewBranch

and switch to that branch using

hg up NewBranch

or switch back to trunk using

hg up default

Upvotes: 7

Andrew
Andrew

Reputation: 14447

In Mercurial, if you go to any particular revision, you can always edit your working copy and commit, thereby making another "head." Merging works on head revisions by default. You can use hg head to see what heads are in your repository. This seems to be the most "idiomatic" way I have found branching to work in Mercurial.

Upvotes: 3

Related Questions