Is there a way to `git submodule add` a repo *without* cloning it?
Asked Answered
B

2

32

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?

Beene answered 2/1, 2016 at 3:34 Comment(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.Monaxial
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.Monaxial
Look at this question: #34152316 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 cloningWhited
But technically it's possible and doesn't seem too cumbersome.Whited
BTW. Indeed having ~30K submodules seems, uhmm, weird. Are you sure that your final goal demands it?Whited
A
34

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).

Absurd answered 22/5, 2016 at 18:52 Comment(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?Encourage
I'm sure that [email protected]:~/submodule.git is active, because the command git clone [email protected]:~/submodule.git works fine.Encourage
It works after if I run git update-index --add --cacheinfo 160000 d020b3a97f131ad11fb15bd8cce1774b0eb54c7b small. Thank you very much.Encourage
This also works for updating an existing submodule to a different revision.Dunfermline
U
-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.

Unroot answered 4/1, 2016 at 12:0 Comment(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.Biomass

© 2022 - 2024 — McMap. All rights reserved.