4

I have the following git repositories

  • Vector
  • Random
  • String

String relies on Vector, and adds it as a submodule. Vector submodules Random. Random has no dependencies.

  • Module: Random
  • Module: Vector
    • Submodule: Random
  • Module: String
    • Submodule: Vector
      • Submodule: Random

When I change something inside of Random submodule inside of Vector, (NOT the actual module Random), it does not automatically update Module: Random or the other Submodule Random's that exist elsewhere.

When I change something inside of Vector (the module), it does not update the Vector in String. If I visit the repository for String, and type git pull, it claims everything is up to date. If I cd inside of submodule Vector and type git pull, only THEN does it actually update my submodule Vector. Ontop of that it wants me to commit changes to the String repository, even though nothing has changed inside of String.

What if I have a repository with 50 submodules? My submodules are going to be changing constantly and I don't want to have to not only pull every single time I want to touch my project but also commit that pull since it was the submodules that changed. There's got to be an easier way to do this.

1
  • As part of the infrastructure, git keeps the commit sha of where you are using the submodule (i.e. why you need to commit in the parent when you update the child - you changed what commit of the submodule is being used!). This is because every "client" of that repository could be using it at a different version. This becomes important where you don't want to change or update one client as you add new features (and bugs), but want others to use the latest. Commented Apr 5, 2017 at 19:12

1 Answer 1

4

As mentioned in git pull options, you should use, from String (the main parent repo) a:

git pull --recurse-submodules=yes
git submodule update --recursive

On top of that it wants me to commit changes to the String repository, even though nothing has changed inside of String.

Sure something has changed: the gitlink (special entry in the repo index) of the submodule Vector.

If you don't want to do that every time you have to refresh the content of String, and just want to do a simple regular git pull, do only once:

git config --global fetch.recurseSubmodules true

And you can automate the submodule update as a post-checkout hook.

Similarly, a simple git push from String would also push any changed submodule, provided you set once:

git config --global push.recurseSubmodules true
Sign up to request clarification or add additional context in comments.

5 Comments

Do I need to do those two lines every time I work on String? My sub-modules are bound to constantly be changing so i guess in order to keep things working I need to pull like that before any type work?
@Hatefiend No, you can automate/configure those steps in order to have to do only a simple basic git pull from String. See my edited answer.
Inside of my module Vector, I did git pull --recurse-submodules=yes and it did correctly notice that Random was changed and so it said Fetching submodule random from.... After that, I typed git submodule update --recursive and nothing appeared to have happened. I cd'ed inside of submodule Random and indeed my changes were not there. I did git status and it said I was behind by one commit. I did a regular git pull and it correctly grabbed the changes. Any ideas why it didn't work?
@Hatefiend did you add and commit in String when you changed Random? Because otherwise, you need to configure Random to follow a branch: stackoverflow.com/a/18799234/6309. Then the command to automate becomes: git submodule update --init --recursive --remote. See more at stackoverflow.com/a/24635535/6309
@Hatefiend Note: if your submodules changes are always on their respective master branch, you only need git submodule update --init --recursive --remote: no special configuration required for those submodules. As to why, see a detailled use case in stackoverflow.com/q/37879715/6309

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.