basics

git clone

Downloads a repository from a remote URL into a new local directory, setting up the remote 'origin' automatically. Includes all commits, branches, and tags by default.

git clone <repository> [<directory>]

Common flags

Flag Purpose
--depth <n> Create a shallow clone with truncated history
--branch <name> Clone a specific branch instead of the default
--recurse-submodules Initialize and clone submodules recursively
--bare Create a bare repository without a working tree
--single-branch Fetch history for only one branch
--filter=blob:none Partial clone that skips file contents until needed

Examples

git clone https://github.com/user/repo.git

Standard clone into ./repo

git clone --depth 1 https://github.com/user/repo.git

Shallow clone with only the latest commit

git clone --branch dev --single-branch [email protected]:user/repo.git

Clone only the dev branch via SSH

Gotcha

Shallow clones (--depth) cannot push to some servers and limit history operations like blame or log; convert with 'git fetch --unshallow' when needed.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge