BugMedic

Git “refusing to merge unrelated histories”: join histories on purpose

Confirm the two histories really belong together before overriding Git's safety check.

By BugMedic editorial teamLast source review: 2026-09-27Windows, macOS, Linux

Git refuses to merge two histories with no common ancestor. Verify the remote is correct and the histories truly belong together, then either re-clone or merge once with --allow-unrelated-histories and resolve the result.

Try these fixes in order

01

Read which command and remote refused

Identify whether the failing command was git pull or git merge, and which remote and branch it targeted. The refusal is a merge safeguard, not a network or permission problem.

02

Verify the remote is the right project

Run git remote -v and confirm the URL is the repository you intend. If it points at the wrong project, fix the remote with git remote set-url instead of forcing a merge of two different codebases.

git remote -v
03

Join the histories deliberately, once

If the histories genuinely belong together, for example a local git init later connected to the team's existing repository, run the merge once with the explicit override and then handle any resulting conflicts like a normal merge.

git pull --allow-unrelated-histories
git merge --allow-unrelated-histories <branch>
04

Re-clone when the projects are actually different

If the histories do not belong together, stop: back up the worktree, clone the correct repository fresh, and copy your files into it. Do not force unrelated projects into one history to make an error go away.

Interpret what you see

Neither history contains any commit from the other side

What it suggests: The local branch and the remote branch started as independent repositories, for example git init locally plus an existing GitHub repo added as remote.

Next check: Run git log --oneline --graph --all -15 on each side and check whether any commit appears in both histories.

The remote repository name or owner looks unfamiliar

What it suggests: You may have added the wrong repository URL as the remote, and the histories are unrelated because they are different projects.

Next check: Run git remote -v and open the URL to confirm it is the project you intend.

The failure happens on git pull but git fetch succeeds

What it suggests: The pull fetched successfully and only the merge step refused, so network and authentication are fine; the decision is purely about history.

Next check: Decide deliberately whether to join the histories or re-clone the correct repository.

Why this happens

  • A local repository was initialized separately and then pointed at an existing remote with its own history.
  • The wrong remote URL was added, so Git tried to merge two genuinely different projects.

Still not working?

Allowing the merge permanently joins the two histories; it cannot be cleanly undone after pushing. On a shared branch, coordinate with the team first, and never use the override flag as a reflex when you are unsure which remote you added.

Official sources

These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.

Related Git guides