Skip to main content
Getting Started

git clone

Copy an existing repository to your local machine

Practical Example

git clone https://github.com/user/repo.git
cd repo
git remote -v  # shows 'origin' -> https://github.com/user/repo.git

Command Overview & How It Works

Downloads the entire repository history and all files from a remote URL, creating a local working directory with the remote automatically configured as 'origin'. The command supports multiple transport protocols: HTTPS (git clone https://github.com/user/repo.git), SSH (git clone git@github.com:user/repo.git), and the Git protocol. Use --depth=1 for a shallow clone that downloads only the latest commit — useful for CI pipelines or large repositories where full history is unnecessary. Use --recurse-submodules to also clone any submodules. Use --branch to clone a specific branch instead of the default HEAD.

Practical Tips

  • Add --depth=1 for a shallow clone when you only need the latest snapshot, such as in a CI pipeline.
  • After cloning, verify the remote with git remote -v — the origin remote is configured automatically.
  • Use --branch to clone a specific branch, and --recurse-submodules when the project relies on submodules.

Related Commands in Getting Started