Part V: Chapter 5.2

git clone

What gets copied. What gets created.

git clone is not magic — it is a precise sequence of steps. Understanding exactly what it creates locally demystifies everything about how remotes, tracking branches, and git pull work.

The Clone Sequence

Step through each phase to see what Git creates on your machine.

git clone https://github.com/badu/myrepo.git
GitHub (remote)

Commit history

9f8aInitial commit
a1b2Add homepage
c4d5Add styles
e6f7Fix nav bug

Branches

main
develop
https://github.com/badu/myrepo.git
Your machine (local)
.git/objects/
empty
.git/refs/remotes/origin/
empty
.git/refs/heads/
empty
Working directory
empty

The Five Things Clone Does

1

Downloads all objects

Every blob, tree, and commit ever created on the remote is downloaded into .git/objects/. You get the full history, not just the latest snapshot.

2

Creates remote-tracking branches

One file per remote branch is written to .git/refs/remotes/origin/. These are the read-only bookmarks recording where each remote branch currently points.

3

Writes .git/config

Adds [remote "origin"] with the URL and refspec, and [branch "main"] with the tracking config. This is how git pull knows where to fetch from.

4

Creates a local branch

Creates .git/refs/heads/main pointing to the same commit as origin/main. This is your first local branch — it tracks the remote.

5

Checks out the working directory

Walks the HEAD commit's tree and writes every file to disk. You end up with a populated working directory ready to use.

Useful Clone Options

Terminal
$# Basic clone (creates ./myrepo/ directory):
$git clone https://github.com/badu/myrepo.git
$# Clone into a specific directory name:
$git clone https://github.com/badu/myrepo.git my-project
$# Shallow clone — only the last N commits (faster for CI):
$git clone --depth 1 https://github.com/badu/myrepo.git
$# Clone a specific branch only:
$git clone --branch develop https://github.com/badu/myrepo.git
$# After cloning, check what tracking is set up:
$git branch -vv
* main c4d5e6f [origin/main] Fix nav bug