How to Check Out Submodules Shallow and in Parallel in CI
actions/checkout can fetch submodules recursively, and shallow depth plus parallel jobs cut the time many submodules add.
Submodules multiply clone time on a large repo. Set submodules: recursive to fetch them, keep each shallow, and fetch them in parallel so the slowest submodule, not the sum, bounds checkout time.
Steps
- Set
submodules: recursiveon checkout to include nested submodules. - Keep
fetch-depth: 1so each submodule is shallow. - Parallelize with
git submodule update --jobsor configuresubmodule.fetchJobs.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 1Parallel shallow update with plain git
Terminal
git submodule update --init --recursive --depth 1 --jobs 4Gotchas
- Private submodules need credentials; provide a token with access or SSH deploy keys.
- A submodule pinned to a commit not on any branch tip can fail a shallow fetch; deepen that one.
Related guides
How to Do a Shallow Clone in CI for a Large RepositorySpeed up checkout of a large repository in GitHub Actions with fetch-depth: 1 for a shallow clone, and learn…
How to Speed Up Checkout of a Large Repository in CITune actions/checkout for a large repository with fetch-depth, filter, sparse-checkout, and fetch-tags to cut…