I been happily using submodules to track all the libraries my project depends from. The thing is I'm using a library called core-plot that only has a public mercurial repository. I can probably mirror it in a readonly Git repository, but is this the best option I got? I had seen there is modules in Mercurial to track things in Git. Someone know if the other way around exists?
-
1It may be simplest to just put the whole checked out mercurial repository under git version control. That way you can update the library via hg whenever you want and still have it under git source control in your project. – Clemens Jan 31 '12 at 20:08
-
The problem with that is you are downloading it when you clone the main repository while submodules are fetched on demand. – dvicino Feb 01 '12 at 16:23
-
Lol, then you create a new git repository and put the whole mercurial stuff in. This git repo can be used as regular git submodule.. problem solved – Clemens Feb 02 '12 at 14:36
-
That what mirroring means, also you can add a hook to your git mirror to fetch from the hg before replying, just was checking if someone had any solution that didn't need a server mirroring. – dvicino Feb 02 '12 at 20:00
2 Answers
Using git-hg.
First, make sure there is a (non-Mercurial) git submodule under your main repository. If you don't have other submodules yet, just create a dummy submodule for some library other than core-plot
, for instance:
main-repo $ git submodule add https://repo.url.com/repo.git repo
Second, clone the core-plot
library into some directory.
main-repo $ git-hg clone https://code.google.com/p/core-plot/ core-plot
Add the new repo to the submodule list.
main-repo $ git submodule add ./core-plot core-plot
main-repo $ git commit -am "added core-plot submodule"
From now on, any clone from this repo will pull both repositories. (After submodule init and update).
Some problems I found out so far are:
- If you push to a bare, then the repo link and the directory will be created in the bare, but the repository will not be cloned inside it and others pulling from that bare will not be able to get the core-plot lib.
- If core-plot needs to be updated the one with the
git-hg
will have togit-hg pull
.
The converse question git submodule from Hg repo? is also asked on StackOverflow. The best answer mentions projects hg-git and git-hg. Another related converse question is, How to deal with Git submodules on a repo that is converted to Mercurial.

- 1
- 1

- 10,960
- 3
- 45
- 74
-
I'm actually aware of those projects. One is cool to use git as submodule of a HG project and the other one's documentation says submodules are not supported. The other thread talks about how to mirror a HG repository into a GIT one so you can submodule from the mirror. – dvicino Feb 01 '12 at 20:47
-
Hmm. I don't see where in the [git-hg Readme](https://github.com/offbytwo/git-hg/blob/master/README.markdown) it says that git-hg doesn't support Mercurial projects as submodules of a git project. – Jim DeLaHunt Feb 01 '12 at 22:27
-
It's not in the readme, but the code: https://github.com/offbytwo/git-hg/blob/master/bin/git-hg There is a list of supported calls, and submodule is none of them, just clone, pull, fetch, push and checkout so far. – dvicino Feb 02 '12 at 01:45
-
1@dvicino, you are managing your main project with git, right? And you want include `core-plot` and treat it as a submodule? But the `core-plot` developers manage it with Mercurial? In that case I believe you don't need to do `git-hg submodule` within the `core-plot` repository. You only do `git-hg fetch` there. You do `git submodule` from the main project's repository instead. That's how I interpret [Pro-git 6.6 "Submodules"](http://progit.org/book/ch6-6.html). Or am I not understanding you? – Jim DeLaHunt Feb 02 '12 at 06:12
-
1Sounds ok. So, what you propose is to create a bare repository in an accessible server (as github) and cron process in a machine with a git repository that git-hg fetches from core-plot and pushes to the other one. Then from my main repo I submodule it. Right? – dvicino Feb 03 '12 at 02:16
-
Okay... Finally I made it work following your steps @jimdelahaunt. The post needs some clarification about step 1 and 2, because they doesn't really work, but with some few changes it does :) I will comment the changes in detail later today and close accept the answer :) THANKS! – dvicino Feb 04 '12 at 17:14
-
Glad to hear you've made it work. Feel free to edit the answer and make it better. That will help the next person. – Jim DeLaHunt Feb 04 '12 at 21:31
-
There it is, I think the 2 open issues can be rephrased to a more generic question, so I will post them later as separated issues. The edition needs to be validated because my score doesn't allow me to do it yet. I will post both questions when edition is approved. Again, THANKS! – dvicino Feb 07 '12 at 01:36
-
5Why is the non-mercurial submodule required? Also, this doesn't appear to work when the git repo is shared via a remote: No one else but the original repo *has* the `./core-plot` submodule. – Josh Bleecher Snyder Jul 12 '12 at 18:29
-
what is the purpose of this step? `main-repo $ git submodule add https://repo.url.com/repo.git repo` – Anentropic May 08 '14 at 10:16
-
@Anentropic: I think you need at least 1 regular git-submodule in order to add a submodule with git-hg. I would like a clarification of this step too... – telephone Jun 29 '14 at 13:13
-
1Is this answer still valid? when I try to add the submodule to the module list using the `git submodule add ./core-plot core-plot` step. However whenever I try this git tries to clone the submodule repo and it fails telling me it doesnt exist. I'd imagine that git-hg clone takes care of the cloning and git submodule add shouldnt need to do the cloning am I wrong? – maguirre May 29 '17 at 02:12
-
@Mischief this *is* a 5-year old answer. That's pretty old, and the software may have changed. Perhaps it's worth your while to phrase your current situation as its own StackOverflow question, and link to here in your description? – Jim DeLaHunt May 29 '17 at 06:28
In my experience, most active non-git projects have an up-to-date git mirror floating around on GitHub. It looks like core-plot
has one too:
https://github.com/djw/core-plot
If you're willing to rely on whoever set that mirror up, it seems like it might be the easiest option to get a submodule in place.

- 2,297
- 1
- 15
- 8
-
1Seriously, this is the best answer, all you need to do is click on the second link that comes up in Google. – Paul de Lange Jul 06 '12 at 08:14
-
4Furthermore you can create such mirrors automatically with https://githgmirror.com/ Disclaimer: my company runs Git-hg Mirror. – Piedone Jan 29 '16 at 15:29
-