ProjectStack
git

fatal: refusing to merge unrelated histories

Git refuses to merge two branches that don't share a common commit history. This usually happens when you initialize a local repo and try to pull from a remote that was separately initialized.

Common causes

  • You ran git init locally and the remote repo was initialized independently (e.g. with a README on GitHub)
  • You're trying to merge two completely separate Git repositories
  • A force-push wiped the shared history on the remote
  • You're pulling from a different repository than the one you branched from

How to fix it

  1. Allow the merge explicitly with the flag: git pull origin main --allow-unrelated-histories
  2. Resolve any merge conflicts that appear, then commit
  3. If starting fresh, clone the remote instead of initializing locally: git clone <url>
  4. If you meant to use a different remote, check your remote URL: git remote -v

Example

fatal: refusing to merge unrelated histories

Running git pull after git init locally and creating a repo on GitHub with an initial README

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.