This error indicates that a Git object file in your repository's .git/objects directory has become corrupted. Recovery typically involves removing the corrupt object and fetching it from a remote repository or backup.
Git stores all data (commits, trees, blobs, and tags) as objects in the `.git/objects` directory. Each object is identified by a unique SHA-1 hash. When an object is first created, it is stored as a "loose object"—a single compressed file named after its hash. For example, an object with hash `abc1234...` would be stored at `.git/objects/ab/c1234...`. When Git reports "loose object is corrupt," it means it cannot read or decompress one of these object files. The file may be empty, truncated, or contain invalid data. Git's internal checksums have detected that the file's contents don't match its expected SHA-1 hash. This corruption is almost never caused by Git itself. It typically results from external factors: power failures during write operations, disk errors, aggressive virus scanners modifying files, cloud sync services (like Dropbox) conflicting with Git's file operations, or filesystem corruption. The good news is that if you have a remote repository or backup, recovery is usually straightforward.
First, run Git's filesystem check to identify all corrupt objects:
git fsck --fullThis will output messages like:
error: loose object 5cde9c3a1fe164cb4d2779d1e0d9d9f4ef18c6a (stored in .git/objects/5c/de9c3a1fe164cb4d2779d1e0d9d9f4ef18c6a) is corruptNote the full object hash—you'll need it for the following steps.
Before attempting any repairs, create a backup of your entire repository including the corrupted state:
# Create a compressed backup
tar -czf ../repo-backup-$(date +%Y%m%d).tar.gz .
# Or simply copy the directory
cp -r . ../repo-backupThis ensures you can start over if something goes wrong during recovery.
If Git identified a specific corrupt object, you can remove it directly. The object path follows the pattern .git/objects/XX/YYYYYY... where XX is the first two characters of the hash:
# For object 5cde9c3a1fe164cb4d2779d1e0d9d9f4ef18c6a
rm .git/objects/5c/de9c3a1fe164cb4d2779d1e0d9d9f4ef18c6aTo remove all empty (zero-byte) objects automatically:
find .git/objects/ -type f -empty -deleteWarning: Only remove objects you've confirmed are corrupt. Don't delete healthy objects.
If you have a remote repository (GitHub, GitLab, Bitbucket, etc.), you can fetch the missing objects:
# Fetch all objects from remote
git fetch origin
# Or fetch with pruning to clean up
git fetch -p originIf this succeeds, verify the repository is now healthy:
git fsck --fullIf fetching doesn't recover the objects, clone a fresh copy and copy the missing objects:
# Clone the repository to a temporary location
git clone <remote-url> ../repo-fresh
# Copy the object from the fresh clone to your repository
# For object 5cde9c3a1fe164cb4d2779d1e0d9d9f4ef18c6a:
cp ../repo-fresh/.git/objects/5c/de9c3a1fe164cb4d2779d1e0d9d9f4ef18c6a \
.git/objects/5c/de9c3a1fe164cb4d2779d1e0d9d9f4ef18c6aAlternatively, unpack all objects from the fresh clone:
cd your-broken-repo
git unpack-objects < ../repo-fresh/.git/objects/pack/*.packIf other methods fail and all your important data is in the remote repository, you can reset your local repository:
# DANGER: This will lose any uncommitted changes and unpushed commits
# First, save any uncommitted work
git stash
# Remove the corrupted objects directory
rm -rf .git/objects
# Re-initialize and fetch from remote
git init
git remote add origin <remote-url>
git fetch origin
git reset --hard origin/main # or origin/masterWarning: This approach loses any local commits that weren't pushed to the remote.
After recovery, verify that your repository is fully functional:
# Check for any remaining corruption
git fsck --full
# Verify you can access history
git log --oneline -10
# Test that basic operations work
git status
git branch -aIf git fsck reports no errors, your repository has been successfully repaired.
### Understanding Git Object Types
Git has four types of objects:
- Blob: File contents
- Tree: Directory listings (file names and references to blobs)
- Commit: Commit metadata and reference to a tree
- Tag: Annotated tag information
When a commit object is corrupt, you may lose that commit. When a blob is corrupt, you lose that specific file version. Tree corruption affects directory structure. Knowing which type is corrupt helps assess the damage.
### Recovering Without a Remote
If you don't have a remote repository:
1. Check for reflog entries: Git keeps a log of recent ref changes that might reference intact copies:
git reflog2. Look for dangling objects: Some objects might be unreferenced but intact:
git fsck --lost-found3. Try git-repair: On some systems, you can install git-repair:
sudo apt install git-repair # Debian/Ubuntu
git-repair --force### Preventing Future Corruption
1. Avoid cloud sync on .git directories: Either exclude .git from sync or move your repositories outside synced folders.
2. Use a UPS or laptop: Prevent power interruptions during Git operations.
3. Run periodic checks: Add git fsck to your workflow or CI pipeline.
4. Push frequently: Always push important work to a remote repository.
5. Monitor disk health: Use SMART monitoring tools to detect failing drives early.
### Pack File Corruption
If the corruption is in a pack file (.git/objects/pack/*.pack) rather than a loose object:
# Move the corrupt pack file
mv .git/objects/pack/pack-*.pack /tmp/
# Try to recover objects from it
git unpack-objects -r < /tmp/pack-*.pack
# Fetch missing objects from remote
git fetch originfatal: 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