# git submodule update Command in CI

> git submodule update fetches and checks out submodules. Reference for --init, --recursive, --depth, and the single command CI uses to pull all nested repos.

Source: https://latchkey.dev/learn/command-reference/git-submodule-update-command-reference  
Updated: 2026-06-26

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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

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

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
