git clone: copy someone else's repository

Updated July 31, 2026

git clone takes a whole existing repository: the full history, every branch, and the files of the latest commit.

It is the first command you run when you join someone else's project or move your own to a new computer. All you need is the address hiding behind the "Code" button on the repository page:

$ git clone https://github.com/username/some-project.git
Cloning into 'some-project'...
remote: Enumerating objects: 128, done.
remote: Total 128 (delta 40), reused 118 (delta 30), pack-reused 0
Receiving objects: 100% (128/128), 24.31 KiB | 4.86 MiB/s, done.
Resolving deltas: 100% (40/40), done.

One command does three things at once. It downloads the history, every commit from every year, not just the latest state. It creates a folder named after the project and lays out the files of the latest commit in it. And it records the server address under the name origin, so git push and git pull work with no extra setup.

$ cd some-project
$ git remote -v
origin	https://github.com/username/some-project.git (fetch)
origin	https://github.com/username/some-project.git (push)

Your own folder name

A second argument sets the name of the directory to create:

$ git clone https://github.com/username/some-project.git my-copy

A dot instead of a name clones straight into the current directory, which has to be empty.

Shallow clone

On big projects the history weighs more than the files do. The --depth 1 flag takes the latest commit only:

$ git clone --depth 1 https://github.com/git/git.git
$ cd git
$ git log --oneline | wc -l
1

In a copy of the git sources made this way the .git directory weighs 14 MB: one commit came down the wire, not twenty years of development. That is fine for reading the code or building the project. It is not fine for working on it: a shallow clone has no history, git log shows a single commit, and some commands refuse to run.

Common mistakes

You do not run git init after git clone. The cloned folder is already a repository and has its own .git. A stray init erases nothing, but it does not make the picture any clearer either.

Git will not clone into a non-empty folder:

$ git clone https://github.com/username/some-project.git ne
fatal: destination path 'ne' already exists and is not an empty directory.

Give the directory another name or clear the existing one. One more trap is cloning a project inside another repository: you end up with a nested repository the outer one does not track.

Where this is in the book

The topic is covered in Chapter 6. GitHub: the cloud and working together.

To practise it by hand, open the Sandbox: a real terminal with git and step checks.