Mercurial clone from a branch
Solution 1
hg clone http://your/repo -r branchname
should do the trick.
Solution 2
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.
Solution 3
hg clone <URL> -b BRANCHNAME
clone single branch, as requested
Solution 4
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
Solution 5
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"
![Abidi](https://i.stack.imgur.com/j9WBF.png?s=256&g=1)
Abidi
Updated on July 09, 2022Comments
-
Abidi almost 2 years
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.
-
Abidi over 13 yearsbasically 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.
-
Jay Maynard K5ZC over 13 yearsI'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 youhg push
, you're pushing your changes to that. Allhg 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. -
Ti Strga over 10 yearsYou might want to mention what the differences are when using this. Apparently there are subtle changes behind the scenes.
-
Nevin Raj Victor over 9 yearsIs there any way to clone code from that branch from one particular revision to the tip of that branch..I tried hg clone [email protected]/TEAM/REPO -r BRANCH_NAME --startrev REVISION_NUMBER ;but its giving an error "hg clone: option --startrev not recognized "
-
O'Rooney about 8 yearsOne 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.
-
John Slegers almost 7 yearsWorks perfectly!