Search code examples
gitgithubgit-submodulesgithub-for-mac

Update git submodules recursively


Maybe this is kind of a dumb question, however I can't seem to wrap my head around this.

I have a repository with 3 submodules, one of them beeing a sub-submodule. All three submodules are third party open source projects on GitHub.

Structure:

My Project
L SubmoduleA
L SubmoduleB
  L SubmoduleC

How do I update all three submodules to the latest available commit (on master branch) on GitHub?

EDIT: Of course I don't want to get the latest commit of SubmoduleC but the one, that is referenced within SubmoduleB. This will change a lot with updates to SubmoduleB.


Solution

  • Since each repo reference a specific SHA1 of a given submodule, you wouldn't be able to update those submodule without having to push them to their respective repos in order to record that new SHA1.

    You would need to control their .gitmodules file in order to record the fact you want those submodules to follow a certain branch, which you can do as I explained in "Git submodules: Specify a branch/tag".

    If those repos and submodules were configured that way, then a simple git submodule update --remote --recursive would update all submodules to their respective branch HEAD.

    But the only way you can control the content of those submodules is to fork their repos and have your project reference as submodule those forks (that you own, and to which you can push back to).