Sub topic 6
Deepening history and converting to a full clone
This chapter assumes you can clone, fetch, and branch in Git, and that you know a shallow clone (made with --depth) holds only the most recent commits. Here you will learn how to add history to a shallow clone when you need it, and how to turn it into a full clone.
Why you would deepen
A shallow clone stores a cut-off point in a file called .git/shallow. Commits at that boundary have no parents in your repository. Commands such as git log, git blame, and git merge-base stop at the boundary. When you hit that limit, you can fetch more history instead of cloning again.
Add a fixed number of commits
git fetch --deepen N moves the boundary back by N commits from where it is now. It is relative to the current depth.
git clone --depth 1 https://example.com/org/big-repo.git
cd big-repo
git fetch --deepen 50
git log --oneline | wc -lAfter the fetch, the log shows up to 51 commits on the current branch's history. The value N is added to the existing depth.
You can also use git fetch --depth N. This sets the depth to N counted from the tip, so it is absolute. Running --depth 50 on a clone that is already at depth 80 would make the history shorter, not longer.
| Option | Meaning | Example effect on a depth-1 clone |
|---|---|---|
| `--deepen 50` | Add 50 commits to the current depth | Depth becomes 51 |
| `--depth 50` | Set the depth to 50 | Depth becomes 50 |
| `--unshallow` | Remove the limit | Full history |
Convert to a full clone
When you need all history, run --unshallow:
git fetch --unshallow
git rev-parse --is-shallow-repositoryThe second command prints false when the conversion is complete. Git downloads every commit that is missing, and it deletes the .git/shallow file.
One detail matters here. A clone made with --single-branch has a fetch rule that names only one branch. --unshallow completes the history for the branches that rule covers. It does not fetch other branches. To get those, change the refspec first:
git remote set-branches origin '*'
git fetch --unshallowIf the repository is not shallow, git fetch --unshallow stops with an error. A full clone does not need it, so this is harmless. In scripts, test first with git rev-parse --is-shallow-repository.
Deepen until you find a commit
Sometimes you do not know how many commits you need. Git can fetch history back to a date or to a point that excludes a given commit:
git fetch --shallow-since=2026-01-01
git fetch --shallow-exclude=v1.0.0--shallow-since fetches commits newer than the date. --shallow-exclude fetches commits that are not reachable from the named branch or tag. The ref must exist on the remote. Both options are useful when a tool needs the history since the last release.
Common errors
- Deepening too little, too often. Each fetch is a network round trip. If you keep guessing, jump to
--unshallow, or use--shallow-since. - Expecting new branches. Deepening does not add branches that the clone's refspec excludes.
- Wrong tool for a partial clone.
--unshallowfills in commit history. It does not download missing file contents from a blobless clone. Those are fetched on demand, as a later chapter explains.
Exercise
You cloned with git clone --depth 1. A teammate asks you to run git blame on a file, but it blames every line on the single commit you have. Which command gives you the full history, and how do you confirm the clone is no longer shallow?
Show answer
Run git fetch --unshallow, then git rev-parse --is-shallow-repository. It prints false when the repository has full history. If you only need a limited amount of history, git fetch --deepen 200 is cheaper.
Exercise
A clone was made with --depth 1 --single-branch --branch main. After git fetch --unshallow, git branch -r still shows only origin/main. Why, and what fixes it?
Show answer
The remote's fetch refspec names only main, so fetching does not bring other branches. Run git remote set-branches origin '*' and then git fetch.