This error indicates repository corruption where a Git tree object references a blob (file) that is missing from the object database. Recovery involves restoring the missing object from another clone or regenerating it from the working directory.
The "broken link from tree to blob" error is reported by `git fsck` when it detects corruption in your Git repository's object database. Git stores your repository data as objects: commits point to trees, trees point to other trees (subdirectories) and blobs (file contents). Each object is identified by a SHA-1 hash of its contents. When Git reports "broken link from tree abc1234 to blob def5678", it means that the tree object (representing a directory) references a blob object (representing a file's contents) that doesn't exist in the object database. The tree "knows" about a file that should be there, but the actual file data is missing. This type of corruption typically occurs due to incomplete Git operations (interrupted clone, fetch, or push), filesystem corruption (disk errors, power loss during write), aggressive garbage collection, or issues with network-attached storage. The repository is in an inconsistent state and cannot fully reconstruct the commit history until the missing objects are recovered or the corrupted references are removed.
First, run a full repository check to understand what's broken:
git fsck --full --name-objectsThe --name-objects flag shows how the broken objects are reachable, helping identify which files are affected:
broken link from tree b5eb6ff... (HEAD~25^{tree}:src/) to blob ec5cf80...This tells you the missing blob was in the src/ directory, 25 commits behind HEAD.
Save the output to analyze which objects are missing:
git fsck --full --name-objects 2>&1 | tee fsck-report.txtCheck how many objects are affected:
grep "broken link" fsck-report.txt | wc -lUse the tree hash from the error to identify the filename:
# Replace TREE_HASH with the tree hash from the error message
git ls-tree TREE_HASHThis lists all files in that tree. Look for the blob hash mentioned in the error to find the filename.
If the tree is also corrupted or you have the commit hash, you can trace back:
# Find commits that modified the area
git log --raw --all -- path/to/suspected/fileYou can also use git to show what the blob should contain if you have any references to it:
git show BLOB_HASHIf the blob exists in any packfile, this will display it.
The most reliable fix is to copy the missing objects from a healthy clone of the same repository:
Option A: If you have access to another local clone:
# In the healthy repository, locate the object
cd /path/to/healthy/repo
git cat-file -t BLOB_HASH # Should output "blob"
# Copy the object file to the corrupted repo
# Objects are stored as: .git/objects/XX/YYYY... (first 2 chars / rest)
cp .git/objects/ec/5cf80... /path/to/corrupted/repo/.git/objects/ec/5cf80...Option B: Fetch from a remote with the objects:
# In the corrupted repository
git fetch --all
# Or fetch from a specific remote
git fetch origin --tagsOption C: Clone fresh and copy objects:
# Clone a fresh copy
git clone --mirror <remote_url> temp-repo.git
# Copy all objects to the corrupted repo
cp -r temp-repo.git/objects/* /path/to/corrupted/repo/.git/objects/After copying, verify the fix:
git fsck --fullIf the file still exists in your working directory (from a recent checkout), you can regenerate the blob:
# Hash the file and write it to the object database
git hash-object -w path/to/file.txtThis outputs the blob's SHA-1 hash. If it matches the missing blob hash from the error, the corruption is fixed.
For multiple files, you can rehash everything:
# Regenerate all blobs from current working directory
find . -type f -not -path './.git/*' -exec git hash-object -w {} \;Then verify:
git fsck --fullNote: This only works if the file content is exactly what Git expects. If the file has changed since the corrupted commit, this won't help for that specific historical blob.
The git-repair tool can automatically attempt to fix repository corruption:
# Install git-repair (Debian/Ubuntu)
sudo apt install git-repair
# Or on macOS with Homebrew
brew install git-repairRun the repair:
# Attempt to repair the repository
git-repair
# Or force repair (may lose some data)
git-repair --forceThe tool will:
1. Try to recover objects from available pack files
2. Fetch missing objects from remotes
3. As a last resort with --force, remove broken references
Verify after repair:
git fsck --full --no-danglingWarning: --force mode may result in data loss if objects cannot be recovered. Use it only when other methods fail.
Sometimes the missing object exists in a pack file but isn't accessible. Try unpacking:
# Move to a backup location first
mkdir -p .git/objects/pack-backup
mv .git/objects/pack/* .git/objects/pack-backup/
# Unpack each pack file
for pack in .git/objects/pack-backup/*.pack; do
git unpack-objects < "$pack"
doneThen repack properly:
git repack -a -dCheck if the corruption is resolved:
git fsck --fullIf the object was present in a pack but the index was corrupted, this can restore it.
If the missing objects cannot be recovered and you need a working repository, you can remove the corrupted references:
Warning: This results in data loss. You'll lose the commits that depend on the missing objects.
# Find all broken links
git fsck --full 2>&1 | grep "broken link"
# Identify which branches/refs contain the corruption
git branch --contains CORRUPTED_COMMIT_HASH
# Delete the corrupted branch or reset it
git branch -D corrupted-branch
# Or reset to before the corruption
git checkout main
git reset --hard LAST_GOOD_COMMITTo clean up all unreachable objects:
# Remove all unreachable objects
git reflog expire --expire=now --all
git gc --prune=nowAs an absolute last resort, reinitialize:
# Backup your working files first!
cp -r . ../backup-repo
# Reinitialize (loses all history)
rm -rf .git
git init
git add .
git commit -m "Reinitialize after repository corruption"After applying fixes, thoroughly verify the repository:
# Full integrity check
git fsck --full --strict --no-dangling
# Verify all refs are valid
git for-each-ref --format='%(refname)' | while read ref; do
git rev-parse --verify "$ref" >/dev/null 2>&1 || echo "Invalid ref: $ref"
done
# Run garbage collection
git gc --aggressive
# Test common operations
git log --oneline -20
git status
git branch -aIf everything passes, push your repaired repository to update remotes:
git push --all origin
git push --tags originTip: Set up regular repository health checks in CI:
# .github/workflows/fsck.yml
name: Repository Health Check
on:
schedule:
- cron: '0 0 * * 0' # Weekly
jobs:
fsck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fsck --fullUnderstanding Git Object Storage: Git stores objects in two formats:
1. Loose objects: Individual files in .git/objects/XX/YYYY... where XX is the first two hex characters of the SHA-1 hash
2. Packed objects: Multiple objects compressed into .git/objects/pack/*.pack files with corresponding .idx index files
Corruption can occur in either format. Pack files are more resilient but harder to repair manually.
Object Reachability: Git considers an object "reachable" if it can be accessed starting from a ref (branch, tag, or special refs like HEAD). Unreachable objects are candidates for garbage collection. The error "broken link from tree to blob" means a reachable tree points to an unreachable (missing) blob.
Preventing Corruption:
- Use reliable storage with proper filesystem support (ext4, XFS with appropriate mount options)
- Ensure clean shutdowns; avoid interrupting Git operations
- Configure core.fsync=true for critical repositories
- Use git config transfer.fsckObjects true to verify objects during transfer
- Regular git fsck checks in CI/CD pipelines
Shallow Clones: Repositories cloned with --depth are inherently "incomplete" and will show many missing objects in fsck. This is normal:
git rev-parse --is-shallow-repository # Returns "true" for shallow clonesServer-Side Corruption: If the corruption is on a remote server (GitHub, GitLab, Bitbucket), contact their support. They may be able to restore from backups or have redundant copies of objects.
Git LFS Considerations: If using Git LFS, "missing blob" errors might actually be missing LFS pointer files or the LFS storage is corrupted. Check git lfs fsck separately.
fatal: bad object in rev-list input
Git rev-list encounters bad or invalid object
fatal: Out of memory, malloc failed during pack operation
Out of memory during Git pack operation
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