-1

When I execute git pull, I want all the submodules to download. According to the winning answer of this question, setting git config --global submodule.recurse true will change the behavior of git pull so that it recurses through the submodules. That is not happening for some reason.

Specifically, I have a repo with a submodule called alib. So I get it into a fresh location.

git config --global submodule.recurse true

mkdir foo
cd foo
git clone https://something.com/MyRepoWithSubmodule.git
git pull

The alib directory is there, however, none of the contents of the submodule are.
What am I missing in order to get the contents of alib to download during git pull

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

1 Answers1

1

The documentation (git-config(1)) says about submodule.recurse (emphasis mine):

submodule.recurse

A boolean indicating if commands should enable the --recurse-submodules option by default. Applies to all commands that support this option (checkout, fetch, grep, pull, push, read-tree, reset, restore and switch) except clone and ls-files...

So, the submodule.recurse option explicitly does not apply to git clone. You need to either git clone --recurse-submodules, or after cloning run git submodule update --init --recursive.

Running git pull immediately after git clone is effectively a no-op (unless someone happens to push something immediately after the clone operation, there won't be any changes to pull).


With submodule.recurse set to true, running git pull will automatically update submodules that have a new commit in the parent repo:

$ git pull
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 278 bytes | 278.00 KiB/s, done.
From localhost:/home/lars/tmp/demo/repo3
   c07f940..044186f  main       -> origin/main
Fetching submodule repo1
From localhost:/home/lars/tmp/demo/repo1
   cf4468f..da359ec  main       -> origin/main
Fetching submodule repo2
Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
Updating c07f940..044186f
Fast-forward
 repo1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/main.
Submodule path 'repo1': rebased into 'da359ec652e59cbd3cbc23ea405cc106519344a8'

See the Fetching submodule ... in response to the git pull.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Understood, but let's say someone makes a change in the submodule, I'd like to get those changes when I run `git pull`. – AngryHacker Aug 03 '22 at 01:23
  • That should work if you have already initialized submodules via `clone` or `submodules init` (and if `git pull` results in new commits that makes changes to submodule versions). – larsks Aug 03 '22 at 01:24
  • I tried the following: `git clone --recurse-submodules repoUrl`, then `git submodule update --init --recursive`. And it did download everything. Then I went into the repo of the submodule and added a file. I tried to do `git pull` and even though it said `fetching submodule alib`, the added file didn't appear. I then went into the `alib` subdirectory (e.g. the submodule) and executed `git pull` - failed because it needed to have , so I ran `git pull origin master` and then it did get the latest file. So it doesn't recurse. You have to do it manually. – AngryHacker Aug 03 '22 at 01:34
  • And what's worse, if I am working in submodule's subdirectory, I can't push back to the submodule repo because the HEAD has been detached when creating the submodule dependency in the first place. – AngryHacker Aug 03 '22 at 01:42
  • 1
    Well, that last bit is just how submodules work. You will be happiest if you treat submodules as read-only. – larsks Aug 03 '22 at 02:14
  • 1
    W/r/t your earlier comment, see my update to the answer. – larsks Aug 03 '22 at 03:16