69

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]
1
  • 2
    it may be similar with 1 submodule, but imagine you have 5+
    – d.raev
    Jan 6, 2018 at 8:29

1 Answer 1

71

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:

4
  • 1
    can you clarify what you mean by "add and commit the new submodule SHA1 reference"
    – Doug
    Jan 31, 2017 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: stackoverflow.com/a/9857021/6309
    – VonC
    Jan 31, 2017 at 18:07
  • Can this answer be more elaborate? I am thinking specifically on the difference between --init and --remote flags.
    – tortal
    Aug 10, 2020 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, 2020 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.