1

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.

DieserJonas
  • 149
  • 11
  • How would that make sense? You want SubmoduleB to be exactly the latest upstream version, but if SubmoduleB's latest upstream version doesn't use SubmoduleC's latest upstream version, you'll necessarily either have an older version of SubmoduleC, or a custom version of SubmoduleB. –  Oct 01 '14 at 22:24
  • You're right, I said that wrong! I don't want the _latest_ commit of the `SubmoduleC`, I want the commit that is referenced within the new commit of `SubmoduleC`. – DieserJonas Oct 02 '14 at 06:22

1 Answers1

0

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).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • **Please see my edit. I didn't express myself correctly:** 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. – DieserJonas Oct 02 '14 at 06:26
  • @DieserJonas in that case, http://stackoverflow.com/a/18799234/6309 allows you to specify that B should update to the latest of a given branch. – VonC Oct 02 '14 at 06:29
  • Thanks for the hint! Now, I've done all the steps and made `SubmoduleA` and `SubmoduleB` track a branch followed by a `git submodule update --remote` which updated `SubmoduleA` and `SubmoduleB`. (Since `SubmoduleC` is a submodule of `SubmoduleB`, I didn't change anything there, correct?) However, now for `SubmoduleB` the GitHub app tells me that it's dirty: `Subproject commit c3e0fd9335f33c5cb415d4fe293217c27e42761e-dirty`. How do I get `SubmoduleC` to update to the commit specified in `SubmoduleB` to make it clean? – DieserJonas Oct 02 '14 at 07:03
  • @DieserJonas If you do any modification in a submodule, you need to add that modif (within the submodule), push to the submodule upstream repo, go back to the parent repo, add, commit, and push as well. – VonC Oct 02 '14 at 07:04
  • @DieserJonas It looks like you missed the `--recursive` option that VonC did include in this answer. –  Oct 02 '14 at 11:13
  • @hvd You're right! That did the trick. So for future updates I just have to run `git submodule update --recursive --remote` to update all the submodules, correct? – DieserJonas Oct 02 '14 at 12:45
  • @DieserJonas yes, that would update all submodules (and sub-submodules) – VonC Oct 02 '14 at 12:54
  • @VonC Thanks a lot! Just read a bit more about the submodules concept and I think I understood it all now. – DieserJonas Oct 02 '14 at 20:16