`error: object file .git/objects/ab/cdef... is empty` / `fatal: bad object HEAD` / `error: bad object refs/heads/main`
AdvancedTroubleshootingPush, Pull and Fetch Errors
Answer
Likely causes → Repository corruption: a crash, disk full, or a killed process left zero-byte or truncated objects.
Diagnose →
git fsck --full
find .git/objects -type f -empty
Fix → Delete the empty objects (find .git/objects -type f -empty -delete), then git fetch origin to re-download missing ones. If a ref is bad, repoint it: git update-ref refs/heads/main origin/main. If it is hopeless, clone again and copy over unpushed work (patch with git format-patch from the backup or reflog).
Prevent → Keep disks from filling, avoid syncing .git with cloud tools (Dropbox, OneDrive), and push often.
More on Push, Pull and Fetch Errors
`! [rejected] main -> main (fetch first)` / `(non-fast-forward)`Beginner`remote: error: GH006: Protected branch update failed for refs/heads/main.`Intermediate`! [rejected] feature -> feature (stale info)` with `--force-with-lease`.Intermediate`You are not currently on a branch.` when running `git pull` or `git push`.Beginner`There is no tracking information for the current branch.` when running `git pull`.Beginner`fatal: The current branch feature has no upstream branch.` on `git push`.Beginner