The "git fetch --unshallow" command fails when converting a shallow clone to a full repository. This typically occurs due to repository corruption, attempting to unshallow an already-complete repository, or CI/CD pipeline configuration issues.
The "git fetch --unshallow" error occurs when Git cannot successfully convert a shallow clone into a full repository with complete history. A shallow clone is a repository that contains only a limited number of recent commits (specified by --depth), which speeds up cloning but lacks the full commit history. When you run "git fetch --unshallow", Git attempts to fetch all missing commits and objects from the remote repository to convert the shallow clone into a complete one. This operation can fail for several reasons: the repository may already be complete (not shallow), there may be corrupted objects in the repository, or network/remote issues may interrupt the fetch process. This error is particularly common in CI/CD environments where shallow clones are used by default to speed up pipeline execution, but tools or scripts later require access to the full repository history for operations like versioning, changelog generation, or branch analysis.
Before attempting to unshallow, check if your repository is actually shallow:
git rev-parse --is-shallow-repositoryIf this returns false, your repository is already complete and doesn't need unshallowing. This is the most common cause of the error.
For Git versions before 2.14, check for the existence of the shallow file:
ls -la .git/shallowIf the file doesn't exist, you have a full clone.
If you get "fatal: error in object: unshallow", the repository's object database may be corrupted. Run a repack to rebuild it:
git repack -dFor more thorough repair:
git repack -aldfAfter repacking, try unshallowing again:
git fetch --unshallowInstead of --unshallow, specify a very large depth value (effectively infinite):
git fetch --depth=2147483647This is the maximum signed 32-bit integer value and tells Git to fetch all available history. This approach can be more reliable than --unshallow in some scenarios.
After successfully unshallowing, you may still only have one branch. To fetch all remote branches, update your remote configuration:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch originOr for a one-time fetch of all branches:
git fetch origin '+refs/heads/*:refs/remotes/origin/*'If this error occurs in CI/CD pipelines, configure your system to perform full clones from the start.
GitHub Actions:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full cloneGitLab CI:
variables:
GIT_DEPTH: 0 # Or use a large number like 1000Azure DevOps:
- checkout: self
fetchDepth: 0CircleCI (.circleci/config.yml):
checkout:
post:
- git fetch --unshallow || trueThe || true ensures the build continues even if unshallow fails because the repo is already complete.
Azure DevOps may have issues with branches/tags that differ only in case (e.g., "Release/1.0.0" vs "release/1.0.0"). Remove conflicting branches:
# List all branches
git branch -a
# Delete conflicting remote branches (adjust as needed)
git push origin --delete Task/branch-name
# Keep only lowercase versionsThis resolves issues introduced by Azure DevOps case sensitivity changes.
For very large repositories where --unshallow times out, deepen the clone incrementally:
git fetch --depth=100
git fetch --depth=500
git fetch --depth=1000
git fetch --unshallowEach step adds more history. If a step fails, the existing clone remains intact and you can retry.
If the shallow repository is irreparably damaged, perform a fresh full clone:
# Backup any local changes
git diff > local-changes.patch
git diff --staged > staged-changes.patch
# Clone fresh without depth restriction
cd ..
rm -rf old-repo
git clone https://github.com/user/repo.git
# Apply backed-up changes if needed
cd repo
git apply ../local-changes.patchUse --no-single-branch if you need all branches from the start:
git clone --no-single-branch https://github.com/user/repo.gitShallow Clone Internals:
Git stores shallow clone information in .git/shallow, which lists commit SHAs that form the "shallow boundary" - commits whose parents have been deliberately excluded. The commit objects themselves are unchanged, but Git ignores parent connections beyond this boundary.
When to Use Shallow Clones:
Shallow clones are ideal for CI/CD builds that only need recent code, Docker image builds, or quick code reviews. They significantly reduce clone time and disk usage for large repositories. However, avoid them when you need full history for operations like:
- Semantic versioning tools (GitVersion, semantic-release)
- Changelog generation
- git blame on older commits
- Bisecting bugs across long histories
Alternative to Shallow Clones (Git 2.25+):
Consider using partial clone with blob filtering instead, which fetches all commits but delays downloading large blobs:
git clone --filter=blob:none https://github.com/user/repo.gitThis provides complete commit history (no unshallowing needed) while still reducing initial clone size.
Debugging Shallow Repository State:
To inspect shallow boundary commits:
cat .git/shallowEach line is a commit SHA at the shallow boundary. The number of lines indicates how many shallow boundaries exist.
Network Optimization:
For slow or unreliable connections, unshallowing can be optimized with:
git config http.postBuffer 524288000 # 500 MB buffer
git config pack.windowMemory "100m"
git fetch --unshallowThis increases buffer sizes to handle large pack files more reliably.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git