How to Clone a Git Repository (git clone)

git clone downloads a complete copy of a remote repository, including its full history, into a new local directory.

Published September 26, 2026

git clone copies a remote repository, including its full history, to your machine and sets up the remote called origin so you can pull and push.

How it works

It creates a new folder, downloads all branches and commits, and checks out the default branch. You can clone over HTTPS or SSH.

Options such as --depth 1 (shallow) or --branch speed things up for large repositories.

Try it

git clone https://github.com/user/repo.git
Cloning into 'repo'...
cd repo && git log --oneline | head -3

Practical examples

Clone via SSH

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

Clone into a custom folder

git clone https://github.com/user/repo.git my-folder

Shallow clone for CI

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

One branch only

git clone --branch develop --single-branch https://github.com/user/repo.git

Common mistakes

  • Cloning inside another repository.
  • Using --depth 1 and later needing full history (use git fetch --unshallow).
  • Forgetting to cd into the new folder.

Key takeaways

  • Clone = download + origin remote.
  • SSH or HTTPS URLs.
  • Shallow clones save time.

FAQ

Clone vs fork?

A fork is a server-side copy on GitHub; clone is a local copy.

How do I get submodules too?

git clone --recurse-submodules <url>.

More Git articles