Skip to content
LatchkeyLatchkey home

git clone Command: Clone Repos in CI

git clone copies a remote repository into a new local directory and sets up an origin remote.

Nearly every pipeline starts with a clone. In CI the goal is usually the smallest, fastest clone that still has the history and files a job needs, so depth and filter flags matter.

Common flags

  • --depth N - shallow clone with only the last N commits (most CI checkouts use --depth 1)
  • --branch <name> / -b - check out a specific branch or tag instead of the default branch
  • --single-branch - fetch only the history of the named branch
  • --filter=blob:none - partial clone that fetches blobs on demand (fast clone, full history)
  • --recurse-submodules - clone and check out submodules in the same step
  • --no-tags - skip downloading tags to shrink the transfer

Example

shell
# Fast CI checkout of a single branch
git clone --depth 1 --branch "${BRANCH}" --single-branch \
  "https://x-access-token:${GITHUB_TOKEN}@github.com/owner/repo.git" repo
cd repo

In CI

A shallow clone (--depth 1) is the single biggest checkout speedup for large repos because it avoids transferring full history. Use --filter=blob:none when you need full commit history (for git describe or nx affected) but not every old blob. For auth, embed a token in the URL since CI has no interactive prompt.

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

  • Use --depth 1 in CI to skip history and make clones dramatically faster.
  • --filter=blob:none keeps full history available while still cloning quickly.
  • Embed a token in the HTTPS URL because CI runners cannot answer credential prompts.

Frequently asked questions

git clone Command: Clone Repos in CI?
Nearly every pipeline starts with a clone. In CI the goal is usually the smallest, fastest clone that still has the history and files a job needs, so depth and filter flags matter.
In CI?
A shallow clone (--depth 1) is the single biggest checkout speedup for large repos because it avoids transferring full history. Use --filter=blob:none when you need full commit history (for git describe or nx affected) but not every old blob. For auth, embed a token in the URL since CI has no interactive prompt.

Related guides

References

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