Skip to content

clone Git Command Guide

The git clone command creates a copy of an existing Git repository, allowing developers to obtain a complete copy of the repository’s history, branches, tags, and files.

Terminal window
git clone [<options>] [--] <repository> [<directory>]
OptionDescription
—bareCreate a bare repository
—mirrorCreate a mirror of the source repository
—depth Create a shallow clone with a history truncated to the specified number of commits
—single-branchClone only a single branch
—no-single-branchClone all branches (default)
—branch , -b Clone specific branch instead of HEAD
—origin , -o Use instead of ‘origin’ for the upstream remote
—recursiveInitialize and clone all submodules
—recurse-submodulesSame as —recursive
—recursive-submodulesInitialize and clone all submodules recursively
—shallow-submodulesClone submodules with —depth=1
—no-shallow-submodulesDo not clone submodules with —depth=1
—template=Directory from which templates are used
—localWhen cloning from local repository, do not use hardlinks
—sharedWhen cloning from local repository, use hardlinks
—archive=Create archive of repository at HEAD in
—dissociateBorrow objects from reference repositories
—separate-git-dir=Place cloned .git directory in
—config =Set config inside the new repository
—quiet, -qOperate quietly
—verbose, -vBe verbose
—progressForce progress reporting
—no-progressSuppress progress reporting
ParameterDescription
URL or path of the repository to clone
Name of the target directory (optional, defaults to repository name)
Terminal window
git clone https://github.com/user/repo.git

Clones the repository into a directory named ‘repo’.

Terminal window
git clone https://github.com/user/repo.git my-project

Clones into directory named ‘my-project’.

Terminal window
git clone -b feature-branch https://github.com/user/repo.git

Clones only the ‘feature-branch’ branch.

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

Creates a shallow clone with only the latest commit.

Terminal window
git clone --recursive https://github.com/user/repo.git

Clones the repository and initializes all submodules.

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

Uses SSH authentication for cloning.

Terminal window
git clone --bare https://github.com/user/repo.git repo.git

Creates a bare repository without a working directory.

Terminal window
git clone --mirror https://github.com/user/repo.git

Creates a complete mirror of the source repository.

Terminal window
git clone --single-branch -b main https://github.com/user/repo.git

Clones only the ‘main’ branch and sets it up for single branch tracking.

To clone a Git repository, use:

Terminal window
git clone <repository-url>

To clone a specific branch, run:

Terminal window
git clone -b <branch-name> <repository-url>

To create a shallow clone, execute:

Terminal window
git clone --depth <number> <repository-url>

How can I clone a repository with submodules?

Section titled “How can I clone a repository with submodules?”

To clone a repository with submodules, use:

Terminal window
git clone --recursive <repository-url>

To clone over SSH, run:

Terminal window
git clone git@<host>:<user>/<repo>.git
  1. Setting up local copies of remote repositories for development
  2. Creating backups of repositories as bare clones
  3. Forking repositories to start new projects
  4. Contributing to open source projects
  5. Setting up continuous integration environments
  6. Creating mirrors for distributed development teams