Sub topic 1
What a Clone Actually Downloads
Prerequisites
Assume you know clone, fetch, pull, and branches. You should also know that Git stores project history as objects: commits, trees, and blobs.
Commits, Trees, and Blobs
A full clone downloads the objects needed for every reachable branch and tag.
- A commit records a snapshot's parent, author, message, and top-level tree.
- A tree records directory contents. It maps file names to blobs and subdirectories to other trees.
- A blob stores the contents of one file version.
A file that changed in 1,000 commits may have about 1,000 blobs. The current checkout uses only some of them, but a full clone normally transfers the complete reachable history.
Why Large Repositories Are Slow to Clone
Clone time and disk use grow with:
- the number of commits and branches,
- the number of historical file versions,
- large binary files,
- tags and other references,
- the data Git must compress, transfer, and index.
The first checkout also expands files into the working tree. Therefore, a repository can be slow even when the current source tree is modest.
Fewer Branches and Tags
Reduce reference discovery before changing history depth. This avoids downloading unrelated branch tips and tag objects, but it still downloads the selected branch's full history.
git clone --single-branch --no-tags --branch main \
https://example.com/org/big-repo.git--single-branch selects one branch. --no-tags avoids importing tags automatically. This is a safe first choice when you need normal history for one branch.
Shallow Clones with `--depth`
A shallow clone limits history. Depth 1 downloads the current commit and its reachable snapshot, not the branch's complete ancestry.
git clone --depth 1 --single-branch --no-tags --branch main \
https://example.com/org/big-repo.git
cd big-repo
git rev-parse --is-shallow-repositoryThe final command prints true.
What Changes in a Shallow Repository
Commands that need older ancestors can give incomplete results or fail. Examples include comparing with a distant commit, finding a merge base, and generating complete history-based release notes. Some operations cannot determine relationships across the shallow boundary.
A shallow clone is useful for builds and quick inspection, but it is not a smaller full clone. Git has deliberately omitted history.
Exercise
What does --depth 1 omit, and why can that affect git log?
Show answer
It omits commits before the current boundary, so git log can show only a truncated history.