33

I have a very long list of repos that I'm trying to make into one parent repo by making them all submodules.

I've tried adding them to .gitmodules manually, and also to .git/config, but it doesn't seem to work.

I've also tried running git submodule sync and git submodule update --init, etc, but with no luck.

Is there a way to trick git into thinking my project has all its (~30K) submodules, without actually needing to clone them all?

5
  • Tricking Git doesn't make a lot of sense. If all you want is a list of repos then a text file would work. Or a build system,. The point of submodules is that your saying that repo is needed and hence why it is cloned. In theory you could do a clone of --depth 1 but it would only work once and only if all the submodules connected to the HEAD of those repos. Then any changes might break things. It just doesn't make much sense. Could you describe your situation better and what you want to accomplish. There is probably a different solution.
    – Sukima
    Commented Jan 2, 2016 at 3:55
  • Why not place your ~30K repos in a Git server like Gitolite or GitHub. Having a master repo seems like the wrong solution to the wrong problem.
    – Sukima
    Commented Jan 2, 2016 at 3:57
  • Look at this question: stackoverflow.com/questions/34151816/… The only problem with "local approach" is URLs in .gitmodules. If you simply use local submodule references, there're changes that you'll get problems on repo cloning Commented Jan 2, 2016 at 4:44
  • But technically it's possible and doesn't seem too cumbersome. Commented Jan 2, 2016 at 4:49
  • BTW. Indeed having ~30K submodules seems, uhmm, weird. Are you sure that your final goal demands it? Commented Jan 2, 2016 at 4:51

2 Answers 2

35

After a long walk on the internet, I found out that you can achieve what you want by writing directly in the git index and create the “gitlink” file type.

git update-index [--add] --cacheinfo 160000 <subrepo commit hash> <submod path>

Also do not forget to write the subrepo in .gitmodules (declare the external path, mostly).

4
  • I tried your solution. I run the code git update-index --add --cacheinfo 160000 46a17436b495636b11492624c46d0fcf8db63458 [email protected]:~/submodule.git, but an errors shows that error: Invalid path '[email protected]:~/submodule.git' fatal: git update-index: --cacheinfo cannot add [email protected]:~/submodule.git. How can I solve it?
    – ramwin
    Commented Mar 3, 2021 at 5:49
  • I'm sure that [email protected]:~/submodule.git is active, because the command git clone [email protected]:~/submodule.git works fine.
    – ramwin
    Commented Mar 3, 2021 at 5:50
  • It works after if I run git update-index --add --cacheinfo 160000 d020b3a97f131ad11fb15bd8cce1774b0eb54c7b small. Thank you very much.
    – ramwin
    Commented Mar 3, 2021 at 9:47
  • This also works for updating an existing submodule to a different revision. Commented Apr 23, 2021 at 8:14
-5

Is there a way to trick git into thinking my project has all its (~30K) submodules, without actually needing to clone them all?

??? ~30K submodules ?
Are u trying to clone all github repositories?

It makes no sense to have so many submodules in a single project.


Is there a way to trick git into thinking my project has all its

Nope, this is what submodule is used for, to contain 3rd party (can be yours as well) dependency which will be managed in its own repository.

enter image description here

As you can see in the image submodule is simply a sub-project inside your project. What you are asking is if there is way to tell git that I have the project while we don't have it at all.

It cant be done.

1
  • 1
    The parent repository stores a reference to a particular commit from the child, but there's no requirement for it to actually have the child repository data. In face, when cloning the parent repository, the default behaviour is not to fetch any data from the child repository at all.
    – mhsmith
    Commented Aug 4, 2018 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.