2

I'm using Git Bash for Windows, version 2.34.1.windows.1. I would like Git to automatically initialize submodules when I do a clone, checkout or pull. I found this question, but the accepted answer, where you configure it with

git config --global submodule.recurse true

does not have any effect. After doing a clone I still have to go into the repository and do

git submodule update --init

to get a submodule.

Is there something I'm missing? Has something changed between those other versions of Git and the one I'm using now? Might the Windows version not honor this setting?

J-bob
  • 8,380
  • 11
  • 52
  • 85
  • 1
    [`submodule.recurse`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse): "*Applies to all commands that support this option… **except clone***" – phd Dec 06 '21 at 18:12
  • @phd Ok I see that now. But then I moved into the new repository, did a `git pull` and still nothing happens. The submodule is still not initialized. – J-bob Dec 06 '21 at 18:23
  • 3
    Unfortunately, the recurse option only applies to the submodules that are there. The clone doesn't create them and therefore they're not there to have recursion applied, so it doesn't apply, which doesn't create them. Bit of a catch-22. You can clone with an explicit `--recurse-submodules` option for bootstrapping. – torek Dec 07 '21 at 03:46
  • Ok thanks for confirming that that is just how git works and I'm not doing something wrong. Are there good reasons for this behavior, or is it just a fact that git handles submodules poorly? – J-bob Dec 07 '21 at 14:39

1 Answers1

0

Are there good reasons for this behavior, or is it just a fact that git handles submodules poorly?

As mentioned before, submodules represent a fixed point in time of the history of a dependent repository. By default, no update.

I mention the new Git 2.34+ setting submodule.stickyRecursiveClone which would allow other commands (git pull, git switch, ...) to use --recurse-submodules without having to add the option explicitely.

But git clone would still require --recurse-submodules to clone the repository.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250