Why does switch of branch update submodule (without explicit pull)?
I just cloned a repository, I never worked on before. It contains submodules, so I did
~/projects/myProject (master) $ git submodule init ~/projects/myProject (master) $ git submodule update
Since I needed a newer version of the submodule, I tried to update via:
~/projects/myProject (master) $ cd subs/mySubmodule ~/projects/myProject/subs/mySubmodule ((no branch)) $ git checkout master ~/projects/myProject/subs/mySubmodule (master) $ git pull
After investigating the situation with removing everything and retry the whole thing, I realized that the submodule was actually updated with the branch switch and by that the pull was not necessary and the response (
Already up-to-date.) was correct.
So why is that?
One Solution collect form web for “Why does switch of branch update submodule (without explicit pull)?”
It’s not quite right to say that the switch updated the submodule. The submodule was updated when you ran
git submodule update. Submodules are a bit weird. As this page says:
git submodule updateto fetch all the data from that project and check
out the appropriate commit listed in your superproject:
So, if you run
git submodule udpate, you already have all the changes from the repo, even if the version you’re seeing isn’t the latest. This is because each branch has a specific commit associated with it. The code you see might be old, but the submodule will already have all the latest data. Then, when you
git checkout master you’re switching to the latest version available, and
git pull doesn’t do anything.