The .gitmodule file only specifies the module repository url. How does git submodule know which version to download? It seems to be always checking out the latest version. Then, how does developers ensure compatibility between the main project and the sub modules?
The .gitmodule file only specifies the module repository url. How does git submodule know
Share
Your submodule is represented as a special entry with a special mode (called a gitlink, see “Nested git repositories without submodules?“):
(See “Checkout past git submodule commit“)
So it isn’t checking out the “LATEST” version, but always a specific SHA1, and it does so in a DETACHED
HEADmode (see “How to make submodule with detachedHEADto be attached to actualHEAD?“.That doesn’t mean you can’t update a submodule, as I explain in “true nature of submodules“.
For more on submodules, and on potentially why you might not want to use them(!), read the sobering article “Why your company shouldn’t use Git submodules“, from Amber Yust (also on SO).
Just one small extract, for kicks and giggles (emphasis mine):
Err… “ouch”.
Note that now a submodule can track the latest from a branch: see “git submodule tracking latest“.