How to combine two projects in Mercurial?

Mercurial

Mercurial Problem Overview


I have two separate mercurial repositories. At this point it makes sense that they "become one" because I want to work on the two projects simultaneously.

I'd really like the two projects to each be a subdirectory in the new repository.

  1. How do I merge the two projects?
  2. Is this a good idea, or should I keep them separate?

It seems I ought to be able to push from one repository to the other... Maybe this is really straight forward?

Mercurial Solutions


Solution 1 - Mercurial

I was able to combine my two repositories in this way:

  1. Use hg clone first_repository to clone one of the repositories.
  2. Use hg pull -f other_repository to pull the code in from the other repository.

The -f (force) flag on the pull is the key -- it says to ignore the fact that the two repositories are not from the same source.

Here are the docs for this feature.

Solution 2 - Mercurial

hg started to have subrepo since 1.3 (2009-07-01). The early versions were incomplete and shaky but now it's pretty usable.

Solution 3 - Mercurial

If you aren't using the same code across the projects, keep them separate. You can set your personal repository of each of those projects to be just a directory apart. Why mix all the branches, merges, and commit comments when you don't have to.

About your edit: Pushing from One repository to Another. You can always use the transplant command. Although, all this is really side stepping your desire to combine the two, so you might feel uncomfortable using my suggestions. Then you can use the forest extension, or something.

hg transplant -s REPOSITORY lower_rev:high_rev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjm.View Question on Stackoverflow
Solution 1 - Mercurialjm.View Answer on Stackoverflow
Solution 2 - MercurialGeoffrey ZhengView Answer on Stackoverflow
Solution 3 - MercurialnlucaroniView Answer on Stackoverflow