I manage a repository with several submodules. For a while now I've been using
$ git submodule foreach git pull origin master
to pull in the latest changes for all of these guys. However, recently I learned about
$ git pull --recurse-submodules
and gave it a try but it seems that changes are only fetched so you need to
$ git submodule update --recursive
in order to actually checkout the changes. However, this last seems to do nothing in my repository despite submodules clearly pulling changes. I also noticed that my submodules are checked out to some commit instead of master or whatever branch.
- Am I doing something improperly?
- Or is this an artifact of the
foreach
way I used to do things? - How can I fix things up so that
pull --recurse-submodules
andsubmodule update --recursive
work as expected?
Best Answer
git submodule update --recursive
is updating the submodules to match the commit in the parent repo. So you need to commit a change to the parent repo for that command to do anything.With this setup:
You make changes in "module", commit, and push them. In "proj", you commit module (it just shows the submodule commit hash changing).
Now when you pull and submodule update, it will update "module" to use the new commit.