git submodule update --remote vs git pull

GitGit Submodules

Git Problem Overview


What is the difference between running

git submodule update --remote

vs

cd <submodule directoy>
git pull

Assuming that the submodule was previously set to track some branch:

git submodule add -b master [URL to Git repo]

Git Solutions


Solution 1 - Git

The difference is:

  • git pull will only update your submodule branch, but it can be any branch that you could have checked out yourself in that submodule repo.
  • git submodule update --remote will only update the branch registered in the .gitmodule, and by default, you will end up with a detached HEAD, unless --rebase or --merge is specified or the key submodule.$name.update is set to rebase, merge or none.

In both cases, you still have to go back to the parent repo, add and commit the new submodule SHA1 reference.
That is because in both instances, the SHA1 of the submodule changes, which means the gitlink (special entry in the index of the parent repo, named after to root folder of the submodule) must be added and committed.

A git submodule update --init --remote is like:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2924714View Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow