🔀 Reading Git Error Messages
4 exercises — read real Git errors and their hint: lines. Rejected pushes, merge conflicts, unrelated histories, and blocked checkouts.
Reading Git errors
- Git often prints a
hint:block right after theerror:— read it, it usually names the exact command to run next fatal:= the command stopped and made no changes;error:= something specific failed, often mid-operation- Most Git "errors" are safety checks, not bugs — Git is refusing to silently discard work
Talking about it out loud (Slack / stand-up)
- "My push got rejected — someone else pushed to main, I need to pull first."
- "There's a merge conflict in cart.js — we both touched the same lines, sorting it now."
- "Git's refusing to merge unrelated histories — I think we set up the remote wrong."
- "I can't switch branches yet, I've got uncommitted changes — let me stash them first."
0 / 4 completed
1 / 4
git push output — rejected (fetch first)
{ex.passage} The push is rejected with "fetch first". What is Git actually protecting against here?
Git is preventing you from overwriting history you haven't seen yet.
A "fetch first" rejection (a non-fast-forward push) means someone else pushed to
The fix — in order of what's usually correct:
A "fetch first" rejection (a non-fast-forward push) means someone else pushed to
main after your last git pull/git fetch. Your local branch and the remote branch have diverged. If Git allowed the push anyway, the remote's newer commits would be lost (or hidden) from the branch pointer.The fix — in order of what's usually correct:
git pull origin main(merges the remote changes in, creating a merge commit if needed), then push againgit pull --rebase origin mainto replay your commits on top of the remote ones, keeping history linear- Never use
git push --forcehere on a shared branch likemain— that discards the other person's commits entirely instead of integrating them