git submodule update vs git submodule sync
update
is basically doing git pull
in each submodule (except without a branch, since the main repo specifies a commit directly).
The tricky one is sync
. Imagine you clone a project with submodules, then later the upstream project changes one of the submodules to point to a different URL.
Your local copy of the submodule will still point to the old URL, since git never allows remote repositories to force a change to local configuration. You need to run git submodule sync
to apply the remote repo's configuration to your local submodule repos.
Note also that, if you are making changes to the submodules, you might want the URLs to mismatch even if the upstream never changed them ... but using multiple remote URLs is probably a better idea for that case.
git submodule update
updates the contents of the submodules. It is effectively running a "git fetch" and "git checkout" in each of your submodules.
git submodule sync
updates the metadata about a submodule to reflect changes in the submodule URL. It re-synchronizes the information in .git/config
with the information in .gitmodules
.