Working with Git submodules
Include support for Git submodules in the global Git configuration
With just a few small changes in the global configuration, the standard functionality of many git commands can be expanded so that any existing submodules are taken into account.
Additional output for git diff
and git status
To see whether a submodule has been updated and to get a list of the commits that have been added to it, git diff
can be called with the --submodule
flag.
The flag can also be added as an option to the global configuration:
git config --global diff.submodule log
So that the updates of the submodules are displayed in a short summary using git status
, add the following option:
git config --global status.submodulesummary true
Update submodules after a git pull
in the main repository
The git pull
command fetches the changes to the submodules recursively by default, but does not update the submodules in the working directory. To add the updates, you have to run git submodule update
.
Alternatively, it is also possible to add the --recurse-submodules
flag to the git pull
command. If you always want to run git pull
with this flag, add another option to the global configuration:
git config --global submodule.recurse true
This setting actually means that not only git pull
is always executed with the --recurse-submodules
flag, but also all other git commands that support this option.
By the way: To check changes in the submodules when pushing the main repository and to not allow the push if the submodules are not up to date, call git push
with the option --recurse-submodules = check
.