git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Why do submodules detach HEAD? (was Re: Incorrect and inconsistent End-Of-Line characters in .gitmodules ...)

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Jul 21, 2021, 22:42 UTC
Message-ID
<9d39da2c-1450-d462-5d80-13112a529c2e@gmail.com>
In-Reply-To
<46F5B91F-4DBE-4F34-9395-7CC808FAC359@gmail.com>
Hi Atharva,
Le 2021-07-21 à 03:26, Atharva Raykar a écrit :
Show 16 quoted lines
> On 18-Jul-2021, at 02:52, Rostislav Krasny <rosti.bsd@gmail.com> wrote:
>>
>>
>> [...]
>> I would like to take this opportunity to ask: why cloning a repository
>> that contains submodules sets this repository branch to its default
>> (master, main, whatever) but all submodules are set into a detached
>> HEAD mode instead of their default branches? This is actually the
>> reason I started to check what happens with the .gitmodules file. What
>> is the point in such an inconsistent behavior? There are a lot of
>> questions about that in Google and it seems most of the users expect
>> different behavior.
> 
> Submodules are cloned along with the parent repository only when
> 'submodule.recurse' is set to true, which I assume is the case for
> your configuration.
Correction: no, 'git clone' always needs to be given the '--recurse-submodules' (or its old
alias, '--recursive') for submodules to be cloned. It does *not* honor
'submodule.recurse' (that's documented at [1]).

Should it honor it ? Some people think yes, but others think no (mostly people that deal with repos with a huge number of submodules which are optional, and thus would not want *all* submodules to be cloned even if 'submodule.recurse' is set) . This has been discussed before, and several tries were done to change that but for now the behaviour remains. I personnally think that marking some submodules as optional should be something that can be tracked in '.gitmodules', and a future version of Git would clone all *non-optional* submodules if 'submodule.recurse' is set (some think it should do so even if it's not set.) The most recent discussion about that, I think, it at [2].

Show 8 quoted lines
> 
> -- 8< --
> 
> I hope that makes sense.
> 
> (Anyone more knowledgeable than me in submodules, feel free to add
> to what I am saying and correct me if I made an error!)
> 

The rest of what you wrote is perfectly clear and correct. Keep up the good work on your GSOC project ! :)

Cheers,
Philippe.

[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse [2] https://lore.kernel.org/git/0fc5c0f7-52f7-fb36-f654-ff5223a8809b@gmail.com/

Previous: Atharva RaykarNext: Rostislav Krasny
Message 5 of 10 in “Incorrect and inconsistent End-Of-Line characters in .gitmodules after "git submodule set-branch --branch <branch_name>"”
  1. Rostislav KrasnyJul 15, 2021
  2. brian m. carlsonJul 16, 2021
  3. Rostislav KrasnyJul 17, 2021
  4. Why do submodules detach HEAD? (was Re: Incorrect and inconsistent End-Of-Line characters in .gitmodules ...)Atharva Raykar, Jul 21, 2021
  5. Philippe BlainJul 21, 2021
  6. Rostislav KrasnyAug 5, 2021
  7. Atharva RaykarAug 5, 2021
  8. Torsten B��gershausenJul 17, 2021
  9. Rostislav KrasnyJul 17, 2021
  10. Torsten B��gershausenJul 18, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.