Git Error Codes & Fixes
Common Git errors when cloning, pushing, and merging. Each guide includes root cause analysis, diagnostic commands, and step-by-step resolution.
Git Error: Permission denied (publickey)
The remote Git server (GitHub, GitLab, etc.) rejected your SSH key — either none was offered, or the one offered isn't authorized.
$ ssh-keygen -t ed25519 -C "you@example.com"Git Error: refusing to merge unrelated histories
Git detected two branches with no common commit ancestor and, by default, refuses to merge them without explicit confirmation.
$ git pull origin main --allow-unrelated-historiesGit Error: failed to push some refs (non-fast-forward)
The remote branch has commits your local branch doesn't have — Git refuses to push until you incorporate them first.
$ git pull origin your-branchGit: You Are in "Detached HEAD" State
You've checked out a specific commit directly instead of a branch — new commits here won't belong to any branch unless you create one.
$ git checkout -b new-branch-name