We have a repository with three named branches, I wanted to clone one of the branches. Is there a mercurial command to do that? If I provide the path (of branch) with hg clone I get 404 error.
Asked
Active
Viewed 4.8k times
5 Answers
107
hg clone http://your/repo -r branchname
should do the trick.

Benjamin Pollack
- 27,594
- 16
- 81
- 105
-
Is there any way to clone code from that branch from one particular revision to the tip of that branch..I tried hg clone https://NAME@bitbucket.org/TEAM/REPO -r BRANCH_NAME --startrev REVISION_NUMBER ;but its giving an error "hg clone: option --startrev not recognized " – Nevin Raj Victor Feb 12 '15 at 04:38
13
Benjamin's right. But is that really what you want to do? In particular, you'll only get the changesets needed to make up that branch, and nothing else - and that would, for example, prevent you from pulling changesets in from the trunk or other branches. You might well be better off just cloning the entire repository and then simply working in the branch you are interested in; this will let you keep your repository in sync with the one you're pulling from more easily.

Jay Maynard K5ZC
- 351
- 2
- 11
-
basically I have always worked on Subversion, I would greatly appreciate if you could point me to a resource that explains this a bit more as most of the resources just talk about HOW to do in hg. – Abidi Dec 28 '10 at 16:24
-
3I'm making that transition myself. The fundamental shift you need to make is that you're no longer working on just a local copy with Mercurial. What you have is a repository, just like the one you're cloning from. When you do `hg pull`, you're actually updating your repository with the changes recorded in the upstream; when you `hg push`, you're pushing your changes to that. All `hg update` does is make the files in your directory reflect the state of the repository for whatever revision or branch tag or whatever you select. – Jay Maynard K5ZC Dec 28 '10 at 16:52
-
One reason to do this is that you're using Mercurial one-way only, to deploy changes to a server for example. In that case you really *don't* want to have the non-production branches being copied over. – O'Rooney Jun 15 '16 at 03:38
5
I know that this post is very old, but I had the same question. I found this trick:
hg clone /path/to/your/repo -r 0
hg pull -u -b branchname

BlaX
- 51
- 1
- 2
-
You might want to mention what the differences are when using this. Apparently there are subtle changes behind the scenes. – Ti Strga Mar 24 '14 at 16:15
4
I'm using Mercurial-4.0.2. In that we can specify the branch name by appending branch name with a # symbol in the clone url.
e.g.
hg clone https://user@cloneurl/my_product#MY_BRANCH
hg clone --verbose https://user@cloneurl/my_product#MY_BRANCH "C:\myCode"

apm
- 525
- 6
- 19