Clone a Git Repository with git clone

Copy a remote repository — code plus full history — into a new local folder in one command.

LinuxdevelopergitcliLow risk
Run git clone https://github.com/example/project.git and cd project to get a working copy with the entire history.

01Command

Command
$ git clone https://github.com/example/project.git && cd project

02What it does

git clone fetches every branch and commit by default and sets up 'origin' as the remote, so pull/push work immediately. On slow connections or huge repos, --depth 1 fetches only the latest commit (shallow clone) and --recurse-submodules also pulls nested repositories; --branch lets you check out a non-default branch straight away. SSH URLs (git@github.com:user/repo.git) authenticate with your key instead of a token.

03Risk

RiskLow risk
Requirementsgit package
!Warning: A shallow clone (--depth) cannot push or fully interact with history until you unshallow it — use it for browsing, not for development you intend to push.

04Undo

Undo
$ rm -rf project

05Sources

  • git-clone — Clone a repository into a new directory
    Git official documentation · community · 2026-09-17
    Evidence: Official docs describe cloning into a new directory, HTTPS/SSH URLs, and options --depth, --branch and --recurse-submodules; confirms 'git clone' and '--depth' appear in the text.
  • git-clone(1) — Debian man page
    Debian manpages · community · 2026-09-17
    Evidence: Man page documents 'git clone' usage with repository URL argument and the --depth option for shallow clones.

Last verified: 2026-09-19 · Category: Developer

06Related solutions