Invalid Object Name
Error message
fatal: invalid object name 'HEAD'
Quick summary
HEAD does not point to a valid commit — most commonly because no commits have been made yet.
Why this happens
The repository was just initialized (git init) with no commits
All commits were removed (e.g. git reset --hard on the first commit)
The .git directory is corrupted
Minimal example
git log # fatal: invalid object name 'HEAD' (no commits yet)git add .
git commit -m "Initial commit"
git log # now worksA freshly initialized repo has no commits, so HEAD is invalid. Make your first commit to fix it.
How to diagnose
Run git log — if it fails, there are no commits
Run git status — it should say 'No commits yet'
Check if .git/HEAD exists and is valid
How to fix
Make your first commit: git add . && git commit -m "Initial commit"
If commits were accidentally removed, check git reflog for recovery
If corrupted, re-clone from the remote
How to prevent
Always make an initial commit after git init before using HEAD references
Be careful with git reset --hard on repositories with few commits