Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule update --remote vs git pull

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] 
like image 622
user2924714 Avatar asked Oct 27 '13 15:10

user2924714


People also ask

What does git submodule update -- Remote do?

For example, submodule update --remote --merge will merge upstream submodule changes into the submodules, while submodule update --merge will merge superproject gitlink changes into the submodules.

Does git pull also update submodules?

With Git 2.34, if the repository is cloned with the --recurse-submodules , a simple git pull will recurse into submodules.

How do you pull changes from a submodule?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .


1 Answers

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:

  • git submodule init: to initialize (checkout) the submodules recorded in the index
  • git submodule update --remote: to pull from the registered branch (or master by default), once the submodule has been initialized (checked out).
like image 69
VonC Avatar answered Oct 05 '22 12:10

VonC