Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … fatal: refusing to merge unrelated histories

'refusing to merge unrelated histories' in Git

The two branches share no common commit, usually a new local repo and a remote created with a README.

Git

What it means

Git won't merge two histories with no shared ancestor by default, because it's usually a mistake: the wrong remote, or a remote initialised separately with a README or licence.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. The remote was created with its own first commit and you have your own

Check:

git log --oneline origin/main | tail -1; git log --oneline main | tail -1

Fix: If it's really the same project, git pull origin main --allow-unrelated-histories once, then resolve conflicts.

2. The remote URL points at the wrong repository

Check:

git remote -v

Fix: git remote set-url origin <right-url>.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors