# git clone Command: Clone Repos in CI

> git clone copies a remote repository into a new directory. Reference for --depth, --branch, --filter, and --recurse-submodules as used to speed up CI checkouts.

Source: https://latchkey.dev/learn/command-reference/git-clone-command-reference  
Updated: 2026-06-26

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

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

---

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
