All commands

git clone

Copy an entire repository — history, refs, branches — to your machine.

What it does

git clone connects to a remote, downloads every object in its object store, and reconstructs the repository locally: all commits, all trees, all blobs, all tags. It then checks out the default branch so you have a working copy, and records the source as origin.

Your machine

local repository

main
everything streams down ↓

Remote origin

everything.git

refs/heads/main

The remote's whole object database streams down; a copy is materialized

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 3

Step 1

Grab the whole project

You point at a remote URL. Everything — every commit, branch, tag — is about to flow down to you.

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

Your machine

local repository

main
everything streams down ↓

Remote origin

everything.git

refs/heads/main

The object database streams down

Under the hood

1

It's a fetch plus a checkout

Under the hood, clone = git fetch (download all reachable objects into your local object store) + git checkout (materialize the default branch into a working tree). One command, two classic operations.

2

Remote-tracking refs are created

Clone writes refs/remotes/origin/main pointing at the remote's default branch, and sets main's upstream to origin/main. That wiring is what makes 'ahead/behind' and straightforward git pull work from day one.

3

All of history comes down

Cloning is full-depth by default: every commit, blob and tree arrives as loose objects or packfiles. That's why your .git folder is often bigger than the checkout — it holds the entire past of the project.

4

--depth skips history for speed

Shallow clones (--depth 1) download only one commit's worth of objects. Great for a quick look, a tax later: many operations lose reachability context and need --unshallow to heal.

Aliases the pros type

Memorize the git clone concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git clone
AliasWhy people use it
g cl

The universal clone alias.

g cl --depth=1

One-commit clone — the CI workflow staple.

Command anatomy

git clone <url> [<dir>]
<url>

HTTPS or SSH URL (https://github.com/org/repo.git).

--depth 1

Shallow clone — just the latest snapshot.

--branch <b>

Skip to a specific branch as the initial checkout.

--bare

Mirror the repo with no working directory (server-side).

When to reach for it

Grabbing a project to work on: git clone git@github.com:user/repo.git.

Creating a backup mirror of a repo with --bare or --mirror.

Speeding up CI by shallow-cloning in build images.

Pro tip

After clone, origin is just a name your git config maps to a URL: `git config --get remote.origin.url`. You can rename it (git remote rename upstream origin) and re-point any remote at will.

Go deeper with