Git repository corrupt incorrect header check; loose object is corrupt
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The Git error incorrect header check together with loose object is corrupt means one of the object files in .git/objects can no longer be decompressed or validated. In practical terms, Git found repository data that does not match the checksum and storage format it expects, usually because of disk corruption, an interrupted write, or a broken copy of the repository.
What a loose object is
Git stores commits, trees, blobs, and tags as content-addressed objects. Some of them live as individual compressed files in .git/objects, and those are called loose objects. Others are packed into packfiles.
When Git reads a loose object, it expects:
- the file to decompress correctly
- the internal header to match the object type and size
- the SHA-derived filename to match the object content
If decompression fails, Git reports errors like incorrect header check. If checksum validation fails, it reports a corrupt object.
Confirm the damage first
Start with a repository check:
This tells you which object is broken and whether the problem is isolated or widespread. If the corruption is broader than one object, stop and think about the underlying storage before trying random fixes.
It is also worth checking whether the corrupted object exists only as a loose object or whether a healthy copy may still exist in a packfile or on a remote.
Recover from a healthy source when possible
If the object exists on a remote or in another local clone, recovery is often straightforward. The safest path is:
- make a backup copy of the damaged repository
- identify the broken object path
- delete only the corrupt loose object file
- fetch from a healthy remote so Git can restore the missing object
The corrupt object path typically looks like:
After backing up the repository, you can remove that one damaged file and fetch again:
This works only if a healthy source still has the object. If the broken object exists only in your damaged clone and has never been pushed elsewhere, recovery becomes harder.
Reclone if the repository is disposable
If the clone has no unique local history and the remote is authoritative, recloning is often the fastest answer:
That is not laziness. It is often the most reliable way to eliminate hidden object-store problems when the remote copy is known to be good.
If you do have local unpushed work, inspect git reflog, stashes, and local branches carefully before abandoning the damaged clone.
Check the machine, not just the repo
Git corruption is often a symptom rather than the root cause. If you see this error more than once, investigate:
- failing disks or SSD issues
- filesystem errors
- flaky network storage
- interrupted backup or sync tools
- antivirus or third-party tools mutating
.git
If the repository lives on a network share or synchronized folder, that environment itself may be unsafe for Git's object database.
Common Pitfalls
The biggest mistake is deleting random files inside .git/objects without first running git fsck and making a backup. Git object storage is precise, so guessing can make recovery harder.
Another mistake is fixing the repository once and ignoring the machine-level cause. If storage is failing, more corruption will follow.
Developers also assume every corruption case can be repaired by git gc or git repack. Those commands are not magic; they depend on having valid objects to work with.
Finally, do not immediately reinitialize .git unless you have accepted that repository history may be lost. A healthy remote or sibling clone is usually the right recovery source.
Summary
- '
loose object is corruptmeans Git found damaged object data in.git/objects.' - Run
git fsck --fullfirst to identify the exact problem. - If a healthy remote or another clone exists, remove only the bad object after backing up and fetch a clean copy.
- Reclone when the local clone has no unique history and the remote is authoritative.
- Investigate disk, filesystem, and storage environment issues so the corruption does not return.
Related reading
- Git repository URL - SSH syntax without absolute path
- git reset --hard HEAD leaves untracked files behind
- git reset --hard HEAD leaves untracked files behind
- Git reset single file in feature branch to be the same as in master/main
- git returns http error 407 from proxy after CONNECT
- git revert back to certain commit
- Git, rewrite previous commit usernames and emails
- Git says a file is unmerged and I can''t commit, but the file seems to be merged
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.