Skip to content
Latchkey

git clone: Usage, Options & Common CI Errors

git clone creates a working copy of a remote repo and sets up origin for you.

Almost every pipeline starts by cloning. The right flags keep clones fast and avoid auth and history surprises.

What it does

git clone copies a repository into a new directory, checks out a working copy of the default branch, and creates a remote named "origin" pointing at the source URL.

Common usage

Terminal
git clone https://github.com/owner/repo.git
git clone --branch v1.2.0 --single-branch https://github.com/owner/repo.git
git clone --depth 1 https://github.com/owner/repo.git
git clone --recurse-submodules https://github.com/owner/repo.git

Options

FlagWhat it does
--depth NShallow clone with the last N commits
--branch <name>Check out a specific branch or tag
--single-branchFetch only the named branch
--recurse-submodulesClone and check out submodules too
--filter=blob:nonePartial clone (blobs on demand)

Common errors in CI

fatal: could not read Username for 'https://github.com': terminal prompts disabled - the clone needs credentials but CI has no TTY. Use a token in the URL or a credential helper, e.g. git clone https://x-access-token:${TOKEN}@github.com/owner/repo.git. For SSH, "Host key verification failed" means the host key is not in known_hosts.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →