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

> git submodule update --init --recursive clones and checks out all nested submodules. Reference for --depth, --remote, and the auth and detached-HEAD errors in CI.

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

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

| Flag | What it does |
| --- | --- |
| --init | Initialize uninitialized submodules first |
| --recursive | Recurse into nested submodules |
| --depth <n> | Shallow-clone each submodule |
| --remote | Update 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
```

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

---

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
