Skip to content
Latchkey

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.

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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →