47

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]
user2924714
  • 1,568
  • 1
  • 16
  • 24

1 Answers1

52

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:

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    can you clarify what you mean by "add and commit the new submodule SHA1 reference" – Doug Jan 31 '17 at 17:58
  • 3
    @Doug That is because of the gitlink: I have edited the answer and added links which illustrate what a gitlink is. You can see a gitlink here: http://stackoverflow.com/a/9857021/6309 – VonC Jan 31 '17 at 18:07
  • Can this answer be more elaborate? I am thinking specifically on the difference between --init and --remote flags. – tortal Aug 10 '20 at 20:25
  • 2
    @tortal 6+ years later, sure, I can expand on that answer. I have edited said answer: let me know if I can add more details to it. – VonC Aug 10 '20 at 22:02