Git Clone

Git clone copies an entire remote repository, including its full history and branches, down to a new directory on your machine.

What Cloning Actually Does

git clone is usually the very first Git command a developer runs when joining a project. It takes a repository URL, downloads a complete copy of the repository's data, including every commit ever made, every branch, and every tag, and unpacks it into a new folder named after the repository. Unlike checking out a single snapshot, cloning gives you the entire history, so you can browse past commits, switch branches, and work offline immediately after the clone finishes.

This is fundamentally different from downloading a plain zip archive of a project's files. A zip download gives you the current state of the code with no memory of how it got there. A clone gives you a fully functional, independent Git repository, indistinguishable in capability from the one it was copied from. You can commit, branch, and even host your own server from a clone.

Basic Usage

Cloning a public repository

$ git clone https://github.com/acme/project.git
Cloning into 'project'...
remote: Enumerating objects: 1204, done.
remote: Counting objects: 100% (1204/1204), done.
remote: Compressing objects: 100% (612/612), done.
Receiving objects: 100% (1204/1204), 3.21 MiB | 5.4 MiB/s, done.
Resolving deltas: 100% (498/498), done.

$ cd project
$ ls
README.md  package.json  src/

By default, Git names the new directory after the last segment of the URL, stripping the .git suffix. If you want the local folder to have a different name, you can pass a second argument specifying the target directory.

Cloning into a custom directory name

$ git clone https://github.com/acme/project.git my-local-copy
Cloning into 'my-local-copy'...
...

$ cd my-local-copy
$ git log --oneline -3
a3f1c9d Fix pagination bug
7b2e001 Add dark mode toggle
d9012ab Initial commit

What You Get After Cloning

  • The complete commit history of the default branch, and typically all remote-tracking branches
  • A remote named origin already configured, pointing at the URL you cloned from
  • A checked-out working copy of the default branch, ready to edit immediately
  • All tags that existed on the remote at clone time
Note: Right after cloning, running git branch will usually show only one local branch, even though git branch -r reveals many remote-tracking branches. Git checks out just the default branch locally; the others exist as references until you check them out yourself.

Shallow Clones for Large Repositories

Some repositories accumulate years of history and can become large to clone in full. The --depth flag creates a shallow clone that only fetches the most recent commits, which can dramatically speed up cloning for CI pipelines or quick one-off inspections where full history is not needed.

Creating a shallow clone

$ git clone --depth 1 https://github.com/acme/large-project.git
Cloning into 'large-project'...
remote: Enumerating objects: 340, done.
Receiving objects: 100% (340/340), 12.88 MiB | 8.1 MiB/s, done.
Note: switching to shallow clone, history is truncated to the latest commit.
Note: Shallow clones are convenient but limited. Commands that need full history, such as git log on older commits or certain rebase operations, may fail or behave unexpectedly until you run git fetch --unshallow.

Cloning a Specific Branch

If you only need one branch rather than the default, the -b flag lets you specify it directly, checking that branch out immediately instead of the default branch.

Cloning only the develop branch

$ git clone -b develop https://github.com/acme/project.git
Cloning into 'project'...
...
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
Switched to a new branch 'develop'