Common Git Errors & How to Fix Them
Common Git Errors & How to Fix Them
Every developer — from first-timers to 10-year veterans — hits these errors. Knowing exactly what each error message means and the one command to fix it is what separates a developer who panics from one who solves it in 30 seconds and moves on.
❌ Error 1: "Please tell me who you are"
Full message: Author identity unknown [...] Please tell me who you are.
Why it happens: You installed Git on a new machine but haven't configured your name and email yet. Git refuses to create a commit without author identity.
Fix:
Then retry your commit.
❌ Error 2: "fatal: not a git repository"
Full message: fatal: not a git repository (or any of the parent directories): .git
Why it happens: You ran a git command in a folder that Git is not tracking — there's no hidden .git folder here.
Fix — Option A: Navigate to the correct project folder:
Fix — Option B: Initialise Git in this folder if it's a new project:
❌ Error 3: "nothing to commit, working tree clean"
Why it happens: You ran git commit but either haven't made any changes, or you forgot to git add first.
Fix: Check what state your files are in, then stage them:
❌ Error 4: "rejected — non-fast-forward"
Full message: ! [rejected] main -> main (non-fast-forward)
Why it happens: A teammate pushed commits to GitHub that you don't have locally. GitHub refuses to accept your push because it would overwrite their work.
Fix:
git push --force to bypass this on a shared branch. That would overwrite your teammate's commits permanently.❌ Error 5: "CONFLICT — Automatic merge failed"
Full message: CONFLICT (content): Merge conflict in src/app.js — Automatic merge failed; fix conflicts and then commit the result.
Why it happens: You and a teammate edited the same lines of the same file. Git cannot decide which version to keep — it needs a human decision.
Fix (step by step):
Open the conflicted file. Find the conflict markers and choose which code to keep:
Delete the markers and keep the correct version. Then finish:
❌ Error 6: "Your branch is ahead of 'origin/main' by N commits"
Why it happens: You've made local commits that haven't been pushed to GitHub yet. This is not technically an error — it's Git informing you of the difference.
Fix:
❌ Error 7: "Your branch is behind 'origin/main' by N commits"
Why it happens: Teammates pushed commits to GitHub that you haven't downloaded yet. Your local branch is outdated.
Fix:
❌ Error 8: "Permission denied (publickey)"
Full message: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
Why it happens: Git is trying to authenticate with GitHub via SSH, but either your SSH key isn't set up, or the public key hasn't been added to your GitHub account.
Fix:
❌ Error 9: "error: failed to push some refs — Updates were rejected"
Why it happens: Usually the same as Error 4 (non-fast-forward), but can also happen if you're pushing a new branch for the first time without setting the upstream.
Fix for new branch:
Fix if you need to sync first:
❌ Error 10: Detached HEAD State
Full message: HEAD detached at abc1234
Why it happens: You ran git checkout on a specific commit hash or tag instead of a branch name. Git is no longer on any branch — you're floating in history.
Fix — go back to main:
Fix — if you made commits in detached HEAD and want to keep them:
Knowledge Check
Ready to test your understanding of Common Git Errors & How to Fix Them?