TechEarl

Git: 'Need to Specify How to Reconcile Divergent Branches' - How to Fix It

Git refuses to pull because your local and remote branches both have new commits. Pick how to combine them: merge or rebase. The one-line fix, what each choice does, plus fetch vs pull, merge conflicts, and unrelated histories.

Ishan KarunaratnePublished ⏱️ 14 min readUpdated
Share thisCopied
Git won't pull because your branch and the remote both have new commits. Fix it with git config pull.rebase, then handle conflicts and unrelated histories.

"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:

bash
git config --global pull.rebase false

Then 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:

text
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:

text
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.

SettingWhat git pull doesHistory shapeGood default for
pull.rebase falseMerge: creates a merge commit joining both linesPreserves the real branching, adds merge commitsBeginners, shared branches, "I just want it to work"
pull.rebase trueRebase: replays your local commits on top of the remote'sLinear, no merge commitsPeople who like clean, straight-line history
pull.ff onlyFast-forward only: refuses to integrate if it cannot fast-forwardNever auto-combines; makes you decide each timePeople 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.

bash
git config --global pull.rebase false
git pull

If you would rather keep a clean, linear history with no merge commits, choose rebase:

bash
git config --global pull.rebase true
git pull

Rebase 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):

bash
git config pull.rebase false

To decide a single pull without saving any config at all, pass the flag directly:

bash
git pull --no-rebase   # merge, just this once
git pull --rebase      # rebase, just this once
git pull --ff-only     # fast-forward only, just this once

A 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.

bash
# 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/main

After 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:

bash
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
Stepgit fetchgit pull --no-rebase (merge)git pull --rebase
Downloads remote commitsYesYesYes
Updates origin/mainYesYesYes
Moves your local branchNoYesYes
Changes working filesNoYesYes
Can create a merge commitNoYes, when histories divergedNo (replays instead)
Can stop on a conflictNoYesYes
Safe with uncommitted workYesRiskyRisky

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.

bash
# 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 mergegit rebase
History shapeBranched, with a join pointLinear, straight line
Merge commitYes, one per diverged merge (none on a fast-forward unless --no-ff)No
Original commitsPreserved exactly (same SHAs)Rewritten (new SHAs)
Safe on shared commitsYesNo, this rewrites history
Conflict handlingResolve once, in one commitResolve per replayed commit
Easy to undoYes (revert the merge commit)Harder (needs the reflog)
Best forIntegrating shared/long-lived branchesCleaning 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:

bash
git push --force-with-lease

Even 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:

text
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
Automatic merge failed; fix conflicts and then commit the result.
A real Git merge conflict and its conflict markers shown in the terminal
A genuine merge conflict: the markers Git writes into the conflicted file.

Nothing is broken; the repository is in a paused "merging" state. Open the file and find the marker block:

text
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:

text
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:

bash
git add config.js
git commit                 # for a merge; Git pre-fills the message
git rebase --continue      # instead, if you were rebasing

Habits 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:

bash
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.

CommandWhat it doesWhen to reach for it
git merge --abortCancels the in-progress merge, restores pre-merge stateYou want out of this merge entirely, cleanly
git checkout --theirs <file>During a merge, takes the incoming branch's version of one file wholesaleYou know one whole file should be their version
git checkout --ours <file>During a merge, keeps your current branch's version of one file wholesaleYou know one whole file should stay yours
git reset --hardDiscards all changes back to the last commitA 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:

text
fatal: refusing to merge unrelated histories

No 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"):

bash
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 main

You 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:

bash
git pull origin main --allow-unrelated-histories

# or in two steps
git fetch origin
git merge origin/main --allow-unrelated-histories

Use 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.

SituationSafe to use --allow-unrelated-histories?
You init'd locally, then pulled a remote that has a README/licenseYes, this is the intended use
You are joining an existing local project to a brand-new remoteYes
You typed the wrong remote URL or branch nameNo, fix the URL first; you do not want this merge
You expected a fast-forward and got this insteadNo, 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

If you are new to Git, choose merge by running git config --global pull.rebase false. Merge never rewrites your existing commits, so it is the safest default. Pick rebase only if you specifically want a clean, linear history and you understand that it gives your local commits new IDs.

Older Git silently made a merge commit when branches diverged on a pull. Git 2.27 started warning about it, and Git 2.34 turned the warning into an error that stops the pull until you pick a strategy. Set the config once and the prompt goes away on that machine.

No. The setting only affects what happens when a pull cannot fast-forward, meaning both your branch and the remote gained new commits. When your branch has not moved locally, Git just fast-forwards as usual regardless of the setting.

Yes. Pass the flag on the command line: git pull --no-rebase for merge, git pull --rebase for rebase, or git pull --ff-only for fast-forward only. A flag always overrides the config for that single pull.

No. git fetch only downloads commits and updates remote-tracking branches like origin/main. Your checked-out branch does not move and your working files are not modified, so it is safe to fetch even with uncommitted changes.

Rebasing rewrites commit identifiers. Once you push, other people may have copies of the original commits. If you rebase and force push, your history and theirs diverge, and the next pull produces duplicate commits and conflicts.

Git lets you, because the markers are just text to Git. Your code will then almost certainly fail to compile or run. Search for the marker symbols before committing a resolved merge.

Not by itself. It only tells Git to merge two histories that share no common commit. The risk is using it without realizing you are pulling from the wrong place. If you understand why the histories are unrelated and want them joined, the flag is safe and intended.

Sources

Authoritative references this article was fact-checked against.

Tagsdivergent branchesGitVersion Controlgit pullgit configgit merge vs rebasegit fetchmerge conflictsunrelated histories

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts