Skip to content
LatchkeyLatchkey home

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 4

In 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.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

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.

Frequently asked questions

git submodule update Command in CI?
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.
In 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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card