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
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.gitOptions
| Flag | What it does |
|---|---|
| --depth N | Shallow clone with the last N commits |
| --branch <name> | Check out a specific branch or tag |
| --single-branch | Fetch only the named branch |
| --recurse-submodules | Clone and check out submodules too |
| --filter=blob:none | Partial 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.