7

I learned that to download submodules with main repository we can use --recursive option when cloning main repository.

I did the same git clone --recursive git@github.com:passion/academy.git

I found that it only create a empty directory of submodule but not downloaded its code.

Do we need to do extra stuff like git submodule update --init --recursive ? If yes then what is the use of --recursive flag when cloning main repository ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
voila
  • 1,594
  • 2
  • 19
  • 38
  • 2
    If you are using Git 1.6.5 or later your `git clone --recursive` should do as you are expecting. Are you using earlier than that version? That is a fairly old version but figured worth asking :D – chrixian Dec 22 '15 at 04:30

2 Answers2

3

If you are using a recent enough git, and it still does not clone submodules, that means those empty folders are not submodules but nested git repo.

A nested repo is recorded in its parent repo as a gitlink, but there would not be any .gitmodules files associated to it.

health-check seem to be a nested git but not sure when cloning give me No submodule mapping found in .gitmodules for path for health-check .. is it necessary for nested git repos to have entry in .gitmodules ?

If you want your nested git repo to be recognized and managed as a submodule, yes.

As illustrated by your next question, it is possible that the lack of path entry in .gitmodules for health-check prevents hellospawn (which seems to be a legit submodule) to be checked out.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I found that I have two sub-directories one is `hellospawn` which is sub-module for sure (entry in .gitmodules ) and another folder `health-check` ( no entry in .gitmodules ). I suspect that `health-check` is a nested repo instead of 'sub-module' . Assume if this is the case then won't --recursive flag pull 'hellspawn' code ? .. I hope I am able to explain the things. – voila Dec 22 '15 at 05:44
  • @voila yes, `--recursive` should clone `hellospawn` (just to be sure, what version of git are you using, on which OS?) – VonC Dec 22 '15 at 05:45
  • @voila also, what is the output of `git ls-tree HEAD hellospawn` – VonC Dec 22 '15 at 05:46
  • Git version `git version 2.6.4` .. I just did a clone of main repo again and last line gave me this `Checking out files: 100% (40517/40517), done. No submodule mapping found in .gitmodules for path 'health-check'` . I didn't get anything in `hellspawn` – voila Dec 22 '15 at 05:48
  • @voila that explains `health-check` for sure. What about `git ls-tree HEAD hellospawn`? – VonC Dec 22 '15 at 05:49
  • 160000 commit 2e5c9cbd00652268ae3e61cde6705ff39aad9202 ./ – voila Dec 22 '15 at 05:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98635/discussion-between-voila-and-vonc). – voila Dec 22 '15 at 05:49
  • @voila ok, so it is a gitlink alright. Maybe it refers to the hellospawn repo in its empty state? Does commit 2e5c9c points to a commit with content? – VonC Dec 22 '15 at 05:50
  • @voila so what was the issue with heath-check? – VonC Dec 22 '15 at 06:15
  • `health-check` seem to be a nested git but not sure when cloning give me `No submodule mapping found in .gitmodules for path for health-check` .. is it necessary for nested git repos to have entry in .gitmodules ? – voila Dec 22 '15 at 06:39
  • I have created a new question which explain my current problem in better way. http://stackoverflow.com/questions/34410024/difference-between-nested-git-repos-and-submodules – voila Dec 22 '15 at 06:54
  • @voila Great! Did you declare the submodule or remove its entry? – VonC Dec 22 '15 at 08:09
  • I will go by adding `health-check` to submodule. – voila Dec 22 '15 at 08:14
  • @voila Excellent! No more "`No submodule mapping found`", and the `git clone --recursive` should complete its task. – VonC Dec 22 '15 at 08:16
0

I had a similar issue. A few things to check:

  1. Check your .gitmodules file:
% cat .gitmodules
[submodule "src/mysubmodule"]
    path = src/mysubmodule
    url = myurl/mysubmodule.git
  1. Check your .git/config file and make sure the submodule url listed is the same as in .gitmodules:
% cat .git/config
...
[submodule "src/mysubmodule"]
    url = myurl/mysubmodule.git
    active = true
  1. Finally, check the url and make sure this is the correct url (should be the same as what you type in a "git clone" of that submodule).
Jerry Chen
  • 321
  • 3
  • 4