Interview Prep/Git & GitHub/Push, Pull and Fetch Errors

`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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Push, Pull and Fetch Errors