Git submodule - How to keep the submodule updated when pulling from the main repo

帅比萌擦擦* 提交于 2019-12-06 07:32:38

then it does not seam like B's active submodule commit (on their local machine) gets automatically changed to the commit that A pushed on branch X, even though A actively committed the changed submodule commit

You need to be sure A committed and push from the submodule, and then add/commit and push from the parent repo (in order to record the new submodule SHA1)

Since Git 1.7.5, git pull should update the submodules as well.
Double-check with a git submodule update --init --recursive

But don't forget that "updating a submodule" would only check out its SHA1, not a branch. Unless a submodule is set to track a branch, and you do a git submodule update --recursive --remote.
Even then, it would pull one branch (X or Y), not both.

A friend just told us that the repo on my friends machine might be broken. So we re-cloned it from Origin and now everything just works.

I'm now looking into tracking branches with submodules, to avoid the "checked out HEAD" issue. Can you recommend that?

As explained in the "True Nature of Submodules", a submodule is always in a detached HEAD mode at first.
You can still force it to follow a branch and update itself: see "git submodule tracking latest".
That means the following command would update the submodule content after pulling a branch said submodule must follow:

git submodule update --remote
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!