Git 2 reference · Remotes

git clone Command (Git)

Copy a repository with its full history and set up origin as the remote; --depth makes a shallow copy.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git clone [--depth N] [-b BRANCH] URL [DIRECTORY]

Parameters

ParameterDescription
--depth N Only the last N commits (faster CI checkouts).
-b BRANCH Check out a specific branch.
--filter=blob:none Partial clone: fetch file contents on demand.

Examples

Clone a repository
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
cd ..
git clone -q app app-copy
git -C app-copy log --oneline
git -C app-copy remote -v | head -1

Output

7f7f133 Initial commit
origin	/tmp/tmpa2oy2arj/app (fetch)

Run this on your computer — see “Get Started” for setup.

A shallow clone
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
for i in 1 2 3; do echo $i > n; git add n; git commit -q -m "c$i"; done; cd ..
git clone -q --depth 1 file://$PWD/app shallow
git -C shallow log --oneline

Output

904a32e c3

Run this on your computer — see “Get Started” for setup.

Was this page helpful?