Skip to content

Bad Object Reference

Error message

                fatal: bad object HEAD
              

Quick summary

The commit hash, branch, or tag you referenced does not exist or is corrupted.

Why this happens

  • The commit hash is misspelled or truncated too short

  • The commit was garbage collected after being orphaned

  • The .git directory is corrupted

  • You referenced a branch or tag that does not exist

Minimal example

✗ Broken code
git checkout abc123  # fatal: bad object abc123
✓ Fixed code
git log --oneline  # find the correct hash
git checkout def4567  # correct hash

The hash abc123 does not exist. Use git log to find the correct commit hash, then checkout.

How to diagnose

  • Verify the hash with git log --oneline | grep <partial-hash>

  • Check if the branch or tag exists with git branch or git tag

  • Run git fsck to check repository integrity

How to fix

  • Use the correct, full or sufficiently-long commit hash

  • If the commit was orphaned, check git reflog to find it

  • If the repository is corrupted, re-clone from the remote

  • Create the missing branch or tag if it should exist

How to prevent

  • Use git log to verify commit hashes before referencing them

  • Run git fsck periodically to check repository health

Related Resources

Related Glossary

Related Lessons

← Back to language