Skip to content
LatchkeyLatchkey home

git submodule update --init --recursive: Usage & CI Errors

git submodule update --init --recursive fetches and checks out every submodule, including nested ones.

A bare clone leaves submodules empty. This one command initializes the config, clones each submodule at the pinned commit, and recurses into submodules-of-submodules - the standard CI bootstrap.

What it does

git submodule update --init reads .gitmodules, registers each submodule, clones any that are missing, and checks out the exact commit the superproject pins. --recursive applies the same process to nested submodules.

Common usage

Terminal
git submodule update --init --recursive
git submodule update --init --recursive --depth 1
git submodule update --remote --merge
git -c submodule.recurse=true clone <url>

Options

FlagWhat it does
--initInitialize uninitialized submodules first
--recursiveRecurse into nested submodules
--depth <n>Shallow-clone each submodule
--remoteUpdate to the remote tracking branch
--jobs <n>Fetch submodules in parallel

Common errors in CI

fatal: could not read Username for ‘https://...’ / "could not get a repository handle for submodule" - a private submodule needs credentials the runner lacks; use a token, insteadOf URL rewrite, or SSH keys with access. Submodules check out at a detached HEAD by design; commits there need a branch to survive.

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

Frequently asked questions

git submodule update --init --recursive: Usage & CI Errors?
A bare clone leaves submodules empty. This one command initializes the config, clones each submodule at the pinned commit, and recurses into submodules-of-submodules - the standard CI bootstrap.
What it does?
git submodule update --init reads .gitmodules, registers each submodule, clones any that are missing, and checks out the exact commit the superproject pins. --recursive applies the same process to nested submodules.
Common errors in CI?
fatal: could not read Username for ‘https://...’ / "could not get a repository handle for submodule" - a private submodule needs credentials the runner lacks; use a token, insteadOf URL rewrite, or SSH keys with access. Submodules check out at a detached HEAD by design; commits there need a branch to survive.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card