`warning: refs/heads/main does not point to a valid object!` or `fatal: your current branch appears to be broken`
AdvancedTroubleshootingLost Work, HEAD and History Problems
Answer
Likely causes → The branch ref points to a missing or corrupt commit: interrupted write, disk problem, or manual editing of .git.
Diagnose →
cat .git/refs/heads/main
git cat-file -t "$(cat .git/refs/heads/main)"
git fsck --full 2>&1 | head
git reflog show main
Fix → Point the ref to a good commit: git update-ref refs/heads/main origin/main, or the last good SHA from the reflog. If objects are missing, git fetch origin restores them from the remote.
Prevent → Push regularly and keep an off-machine copy of unpublished work.
More on Lost Work, HEAD and History Problems
`fatal: Unable to create '/repo/.git/index.lock': File exists.`BeginnerYou added a file to `.gitignore`, but `git status` still shows it as modified.Beginner`fatal: your current branch 'main' does not have any commits yet`Beginner`Author identity unknown *** Please tell me who you are.` and `fatal: unable to auto-detect email address`Beginner`fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.`BeginnerYour commits do not show on your GitHub profile contribution graph.Intermediate