Non-fast-forward pushGit rejects pushes when the remote has commits you don't have locally. This prevents accidentally overwriting someone else's work. You must pull first to reconcile.
Divergent historyWhen two people commit to the same branch based on the same ancestor, their histories diverge. Git cannot fast-forward because neither side is a direct ancestor of the other.
git pull (fetch + merge)Pulling fetches remote commits and merges them into your local branch, creating a merge commit that reconciles both lines of history. After this, push succeeds.
📖 Story
You and a teammate both committed on main while working on separate features. When you try to push, Git rejects it: the remote has commits you don't have locally.
You need to pull the remote changes and reconcile the divergence. git pull fetches the remote work and merges it in, creating a merge commit that records both lines of history.
Then you push again — this time it succeeds.
This is the most common "git panic" moment for developers — and once you understand it, you'll never dread push rejection again.
Check the local and remote history
Run git log --oneline --all --graph. Your local main has "Add CI config" but the remote has a different commit "Add Makefile" from your teammate. They diverged from the same base.
● Check the local and remote history
○ Attempt to push (will be rejected in real life)
○ Option 1: Pull with merge to reconcile
○ Verify the merge commit
○ Push again — this time it succeeds
Terminal
📘 Starting tutorial: Diverged History
Your push was rejected — now what? Reconcile divergent histories with git pull and merge.