"You have divergent branches and need to specify how to reconcile them" means your local branch and the remote branch have both gained new commits since they last matched, and Git will not guess whether to combine them with a merge or a rebase. Tell it which you want. The fastest one-line fix is to default to merge:
git config --global pull.rebase falseThen run git pull again. That is it. Below I explain why the message appears and what the merge-versus-rebase choice changes, then cover the problems that come right after it: how git pull differs from git fetch, resolving the merge conflicts a pull can raise, and the related "refusing to merge unrelated histories" error.
What the error looks like
When you run git pull and the two branches have diverged, current Git prints this and refuses to continue:
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
fatal: Need to specify how to reconcile divergent branches.The hint is the fix, written right into the error. You just have to pick one of the three lines.
What "divergent branches" actually means
A git pull is two steps: fetch the remote's commits, then integrate them into your current branch. When your branch has not changed locally, that integration is trivial: Git just fast-forwards your branch pointer to the remote's tip. No new commit, no decision.
The trouble starts when both sides have moved. Say you and a teammate both branched from the same commit. They pushed a commit to origin/main; meanwhile you committed locally to main without pulling first. Now neither branch is an ancestor of the other. They have diverged. Git cannot fast-forward, so it has to genuinely combine two lines of history, and there are two valid ways to do that. That is the decision Git is refusing to make for you. The very same divergence, seen from the other direction, is what produces the non-fast-forward push that blocks you when you try to push instead of pull.
If this is unfamiliar territory, my walkthrough of what branches are and how they move covers the underlying model, and git pull vs git fetch below explains why a pull is really a fetch plus an integration step.
Why Git started demanding this
Older Git silently created a merge commit when a plain git pull hit divergent branches. That default was convenient but quietly opinionated: a lot of people ended up with a history full of "Merge branch 'main' of github.com:..." commits they never meant to make.
Git 2.27 (mid-2020) started warning when you pulled a diverged branch without saying how to reconcile it, but still completed the pull with the default merge:
warning: Pulling without specifying how to reconcile divergent branches is
discouraged.Git 2.34 (late 2021) turned that into the hard error above: git pull now aborts instead of guessing. The error is not a bug or a broken repo. It is Git declining to pick a workflow on your behalf. Set the config once and you will not see it again on that machine.
The three options, and which to pick
Each hint line maps to a different way of integrating the remote commits.
| Setting | What git pull does | History shape | Good default for |
|---|---|---|---|
pull.rebase false | Merge: creates a merge commit joining both lines | Preserves the real branching, adds merge commits | Beginners, shared branches, "I just want it to work" |
pull.rebase true | Rebase: replays your local commits on top of the remote's | Linear, no merge commits | People who like clean, straight-line history |
pull.ff only | Fast-forward only: refuses to integrate if it cannot fast-forward | Never auto-combines; makes you decide each time | People who want to be forced to choose manually |
If you are new to Git, set pull.rebase false. Merge is the safest mental model: your commits stay exactly as you made them, the remote's commits stay as they are, and a single merge commit ties the two together. Nothing gets rewritten.
git config --global pull.rebase false
git pullIf you would rather keep a clean, linear history with no merge commits, choose rebase:
git config --global pull.rebase true
git pullRebase takes the commits you made locally, sets them aside, fast-forwards your branch to the remote tip, then re-applies your commits one by one on top. The end result reads as a straight line, but it rewrites your local commits (they get new commit IDs). That is fine for commits you have not pushed anywhere; it is the reason you should never rebase commits other people have already pulled. I go deeper on the trade-off in git merge vs git rebase below.
The third option, pull.ff only, tells Git to only ever fast-forward. If it cannot (because the branches diverged), it stops and does nothing, leaving you to run git merge or git rebase by hand. It is the most explicit of the three and a reasonable choice once you understand the other two.
Global, per-repo, or per-pull
--global writes the setting to your ~/.gitconfig so every repository on the machine uses it. That is usually what you want; the choice is a personal workflow preference, not something that should differ per project. This config only governs how a pull integrates; if the branch you are on has no remote counterpart at all, you will instead need to set its upstream tracking branch before a bare git pull knows where to pull from.
To set it for just the current repository (drop --global):
git config pull.rebase falseTo decide a single pull without saving any config at all, pass the flag directly:
git pull --no-rebase # merge, just this once
git pull --rebase # rebase, just this once
git pull --ff-only # fast-forward only, just this onceA command-line flag always wins over the config, so git pull --rebase rebases even if your config says pull.rebase false. If a pull goes wrong part-way, git rebase --abort or git merge --abort returns you to where you started.
git pull vs git fetch
git fetch downloads new commits from the remote and updates your remote-tracking branches, but leaves your working files and your current branch exactly as they are. git pull does that same fetch and then integrates the new commits into the branch you have checked out. With no pull.rebase or pull.ff setting, current Git only fast-forwards: if your branch has diverged, it stops with the divergent-branches error above instead of choosing for you. With pull.rebase false (or --no-rebase) it merges, and with pull.rebase true (or --rebase) it rebases. So fetch is read-only against your work, and pull modifies it.
# Download remote changes, touch nothing in your working tree
git fetch origin
# Download remote changes AND merge them into the current branch
git pull --no-rebase origin main
# is roughly equivalent to:
git fetch origin
git merge origin/mainAfter a fetch, your local main and the remote's version are two separate pointers; the remote's is visible as origin/main under refs/remotes/. You can compare them before deciding anything:
git log main..origin/main --oneline # commits the remote has that you don't
git diff main origin/main # the actual file changes coming in| Step | git fetch | git pull --no-rebase (merge) | git pull --rebase |
|---|---|---|---|
| Downloads remote commits | Yes | Yes | Yes |
Updates origin/main | Yes | Yes | Yes |
| Moves your local branch | No | Yes | Yes |
| Changes working files | No | Yes | Yes |
| Can create a merge commit | No | Yes, when histories diverged | No (replays instead) |
| Can stop on a conflict | No | Yes | Yes |
| Safe with uncommitted work | Yes | Risky | Risky |
The bottom rows are why this matters. With uncommitted changes in files the incoming commits touch, a pull can refuse with your local changes would be overwritten by merge. Fetching first gives you a decision point: fetch, run git status and git log --oneline main..origin/main, then git merge origin/main (or stash first) on your own terms.
My rule of thumb: use git fetch when you want to know what is on the remote without integrating it yet; use git pull on a clean branch when you just want it integrated now; use git pull --rebase on a shared branch where you want history linear. One more fetch trick: git fetch --prune origin drops remote-tracking branches that were deleted upstream, which a plain git pull does not do by default.
git merge vs git rebase
Both integrate changes from one branch into another; the difference is what they do to history. git merge preserves the true history; when the branches have diverged it ties them together with a new merge commit, and when your branch has no commits of its own it just fast-forwards the pointer (no merge commit unless you pass --no-ff). git rebase rewrites your commits so they sit on top of the other branch, producing a straight line with no merge commit.
# Merge: a new commit with two parents joins the lines
git checkout main
git merge feature
# Rebase: replay feature's commits on top of the latest main
git checkout feature
git rebase main| git merge | git rebase | |
|---|---|---|
| History shape | Branched, with a join point | Linear, straight line |
| Merge commit | Yes, one per diverged merge (none on a fast-forward unless --no-ff) | No |
| Original commits | Preserved exactly (same SHAs) | Rewritten (new SHAs) |
| Safe on shared commits | Yes | No, this rewrites history |
| Conflict handling | Resolve once, in one commit | Resolve per replayed commit |
| Easy to undo | Yes (revert the merge commit) | Harder (needs the reflog) |
| Best for | Integrating shared/long-lived branches | Cleaning up your own local work |
Merge is the honest record; rebase is the tidy story. Use merge when the branch is public, when you want the merge commit as an audit anchor for a reviewed pull request, or when you want a bad feature to be undoable by reverting one commit. Use rebase to keep a private feature branch current with main without sprinkling merge commits through it, and to tidy local commits before anyone sees them (squashing with interactive rebase); a linear log is also easier for git bisect.
The golden rule: never rebase shared commits
Rebase does not move commits; it creates new ones with the same content but different SHAs and abandons the originals. If a teammate already pulled the originals, your histories silently fork, and the next push or pull turns into duplicate commits and conflicts. Rebase commits that live only in your local repository. If you rebase a branch you already pushed, the only way to update the remote is a force push, and the lease variant refuses if someone else pushed in the meantime:
git push --force-with-leaseEven then, force-push a branch other people use only by agreement. If you rebase something you wish you had not, the old commits stay in the reflog for a while; see recovering lost commits with git reflog.
A practical default for small teams: rebase your local feature branch to keep it current and clean, then merge the pull request into main so shared history stays append-only.
How to resolve merge conflicts
Whichever strategy you pick, a merge or rebase can still stop with a conflict when both sides changed the same lines of the same file. Git cannot guess which version you want, so it pauses:
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
Automatic merge failed; fix conflicts and then commit the result.
Nothing is broken; the repository is in a paused "merging" state. Open the file and find the marker block:
const port = 3000;
<<<<<<< HEAD
const host = "localhost";
const timeout = 5000;
=======
const host = "0.0.0.0";
const timeout = 30000;
>>>>>>> feature-branch
const debug = false;Between <<<<<<< HEAD and ======= is your current branch; between ======= and >>>>>>> feature-branch is the branch you are merging in. Lines outside the markers merged cleanly. Edit the block to exactly the code you want and delete all three marker lines. Say you want their host but your timeout:
const port = 3000;
const host = "0.0.0.0";
const timeout = 5000;
const debug = false;Then stage each resolved file (staging is how you tell Git "this one is resolved") and finish:
git add config.js
git commit # for a merge; Git pre-fills the message
git rebase --continue # instead, if you were rebasingHabits that save pain: git status lists every conflicted file under "Unmerged paths," so work through them one at a time; grep for <<<<<<< before committing, because Git will happily commit a stray marker; and do not just keep both sides unless that is genuinely correct.
For a big, overlapping conflict, a visual three-way tool helps. git mergetool opens whichever tool you configured (VS Code, Meld, KDiff3, Beyond Compare, vimdiff, and others) and marks files resolved when you save. To use VS Code:
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'Older Git left .orig backup files behind; git config --global mergetool.keepBackup false stops them.
| Command | What it does | When to reach for it |
|---|---|---|
git merge --abort | Cancels the in-progress merge, restores pre-merge state | You want out of this merge entirely, cleanly |
git checkout --theirs <file> | During a merge, takes the incoming branch's version of one file wholesale | You know one whole file should be their version |
git checkout --ours <file> | During a merge, keeps your current branch's version of one file wholesale | You know one whole file should stay yours |
git reset --hard | Discards all changes back to the last commit | A blunt last resort; loses uncommitted work |
Those --ours/--theirs meanings are for a merge. During a rebase the sides are swapped: --ours is the upstream branch plus the commits replayed so far, and --theirs is the commit from your own branch being replayed. So in a rebase conflict, git checkout --theirs <file> keeps your version.
git merge --abort is safe as long as your working tree was clean before the merge (commit or stash work in progress first). During a rebase, the escape hatch is git rebase --abort. If you keep hitting conflicts because a branch drifted far from main, the real fix is smaller, more frequent merges.
Fix "refusing to merge unrelated histories"
A different pull error shows up when the two branches share no common commit at all:
fatal: refusing to merge unrelated historiesNo commit is created and nothing changes. Every merge needs a common ancestor as its baseline, and here there is none. The classic way to get here is running git init locally, committing, and then pulling a remote that already has its own root commit (for example one GitHub created when you ticked "Add a README"):
git init
git add README.md
git commit -m "Initial commit"
git remote add origin git@github.com:you/my-project.git
git pull origin mainYou can also hit it after re-initializing a repo with rm -rf .git && git init, after rewriting history so heavily that nothing is shared with the remote, or when merging a branch imported from a different project. If the histories really should be joined, allow it explicitly:
git pull origin main --allow-unrelated-histories
# or in two steps
git fetch origin
git merge origin/main --allow-unrelated-historiesUse master instead of main if that is the remote's branch name. Because the two sides usually touch different files, you typically get a clean merge commit; if both edited the same file (often README.md), you get a normal conflict to resolve as above. Older Git merged unrelated histories silently; Git 2.9 (June 2016) flipped the default to refuse unless you opt in, because people kept merging two unrelated projects after pointing at the wrong remote.
| Situation | Safe to use --allow-unrelated-histories? |
|---|---|
| You init'd locally, then pulled a remote that has a README/license | Yes, this is the intended use |
| You are joining an existing local project to a brand-new remote | Yes |
| You typed the wrong remote URL or branch name | No, fix the URL first; you do not want this merge |
| You expected a fast-forward and got this instead | No, stop and check git remote -v and git branch -a |
The cleanest way to never see it is to clone an existing remote instead of running git init, since a clone shares the remote's history from the first commit. My guide on starting work on an existing Git project walks through that flow.
A safer habit: pull before you commit
The divergent-branches error is fundamentally a "you and the remote moved at the same time" situation. You can sidestep it most of the time by pulling before you start committing, so your local branch begins from the current remote tip. When unfinished work is in the way, git stash lets you set it aside, pull cleanly, and reapply it on top.
For the broader picture, see the Git for beginners hub. And if you keep ending up with diverged history on a shared branch, it is worth reading how teams structure their flow in Git branching strategies for teams.
FAQ
Sources
Authoritative references this article was fact-checked against.
- git-config: pull.rebase, pull.ff - official Git documentationgit-scm.com
- git-pull - official Git documentationgit-scm.com
- Pro Git: Git Branching - Rebasinggit-scm.com
- git-rebase, official Git documentationgit-scm.com
- git-merge, official Git documentationgit-scm.com
- git-fetch: official Git documentationgit-scm.com
- Pro Git: Remote Branchesgit-scm.com
- Git 2.9.0 release notes (introduced --allow-unrelated-histories)github.com
- Pro Git: Basic Branching and Merginggit-scm.com
- git-mergetool: Git official documentationgit-scm.com





