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 repoIn 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
git fetch Command: Update Refs in CIgit fetch downloads objects and refs from a remote without merging. Reference for --depth, --unshallow, --tag…
git submodule update Command in CIgit submodule update fetches and checks out submodules. Reference for --init, --recursive, --depth, and the s…
git sparse-checkout Command in CIgit sparse-checkout limits the working tree to selected paths. Reference for init, set, and cone mode to chec…
git checkout Command: Switch Refs in CIgit checkout switches branches or restores files. Reference for checking out a branch, --detach, and -b to cr…