git submodule update Command in CI
git submodule update checks out each submodule at the commit recorded by the superproject.
Repos with submodules need an extra step after clone to populate them. CI almost always runs the init plus recursive form so nested dependencies are present before the build.
Common flags
--init- initialize any submodules that have not been set up yet--recursive- recurse into nested submodules (submodules of submodules)--depth N- shallow-fetch submodule history to speed up CI--remote- update to the latest commit on the submodule branch instead of the pinned SHA--jobs N/-j N- clone or fetch submodules in parallel
Example
shell
# Populate all submodules after a clone in CI
git submodule update --init --recursive --depth 1 --jobs 4In CI
If a build complains about missing headers or empty submodule directories, the pipeline forgot --init --recursive. Add --depth 1 to keep submodule fetches shallow and --jobs to parallelize when there are many.
Key takeaways
- git submodule update --init --recursive is the standard CI line to populate nested repos.
- --depth 1 keeps submodule fetches fast, mirroring the shallow superproject clone.
- Empty submodule dirs in CI almost always mean the init step was skipped.
Related guides
git clone Command: Clone Repos in CIgit clone copies a remote repository into a new directory. Reference for --depth, --branch, --filter, and --r…
git fetch Command: Update Refs in CIgit fetch downloads objects and refs from a remote without merging. Reference for --depth, --unshallow, --tag…
git config Command: Configure Git in CIgit config reads and writes Git settings. Reference for user.email, --global, and credential.helper to set up…
git ls-files Command: List Tracked Files in CIgit ls-files lists files in the index. Reference for listing tracked, ignored, or modified files to drive lin…