Search notes:

git submodule

Initialize, update or inspect submodules.

After cloning

Get all submodules after freshly cloning a repsitory
git submodule update --init --force --remote

updating submodules

git submodule update (executed in the superproject's directory) updates the submodule(s) to the commit that is specified in the index of the superproject.
A submodule can be updated to its remote's latest commit by going into the submodule and executing and pulling it from there:
cd submod

# HEAD might be detached, or pointing to another branch:
git checkout master

git pull

cd ..
git commit -am "Updated submodule to most recent version"
When dealing with multiple submodules or to make things easier, there is also:
git submodule foreach git pull origin master

foreach

git submodule foreach … executes a shell command in each checked out submodule.
When executed in (typical?) git installation on Windows, it executes the command in bash (which is installed with git).
Git provides a few shell variables that can be used in the foreach command:
$name The name of the relevant submodule section in .gitmodules
$toplevel The absolute path to the top-level of the immediate superproject.
$sm_path The path of the submodule as recorded in the immediate superproject
$displaypath The relative path from the current working directory to the submodules root directory
$sha The commit as recorded in the immediate superproject,
foreach has the two options
git submodule foreach --quiet 'echo $SHELL - $toplevel - $name - $sm_path - $displaypath - $sha1'

Just update the submodules

git pull
git submodule update --recursive

See also

git clone --recurse-submodules …
git commands

Index