I have a parent repo A and submodule repo B, which is checked out at the latest commit on master. I've already ran a git submodule update --init --recursive
in repo A, so my submodule is already inside it. I know I can throw a --remote
flag onto that command to get it to update from the latest commit, but what I haven't been able to figure out is how to change the submodule commit # such that whenever someone else runs a git submodule update --init --recursive
, it will update from the latest commit in the submodule as well. Any ideas? Thanks.

- 31
- 6
2 Answers
git submodule update --init --recursive
, it will update from the latest commit in the submodule as well.
No, that command only checks out the submodule at is recorded gitlink (special entry in the parent repo).
You need to add the --remote
to force the branch update (git pull within th submodule)
But keep in mind any submodule would be updated, defaulting to their upstream master branch if no submodule.<path>.<branch>
is found in the .gitmodules
.
See "Git: track branch in submodule but commit in other submodule (possibly nested)".
Solved by:
1) cd into submodule
2) since the last submodule update had me on a commit that wasn't the latest, I just checked out the latest commit (git checkout [commit_hash]
)
3) cd out of there and back into the parent repo
4) git add submodule --> commit --> push

- 31
- 6
-
You don't need that: if your submodule is set to track a branch (that is if it has a `submodule.
. – VonC Mar 16 '17 at 22:20` in its `.gitmodules`) the `--remote` is enough.