git submodule update --remote vs git pull

user2924714 picture user2924714 · Oct 27, 2013 · Viewed 34k times · Source

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]

Answer

VonC picture VonC · Oct 27, 2013

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: