Categories
git rebase

Git refusing to merge unrelated histories on rebase

3177

During git rebase origin/development the following error message is shown from Git:

fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef

My Git version is 2.9.0. It used to work fine in the previous version.

How can I continue this rebase allowing unrelated histories with the forced flag introduced in the new release?

7

  • 18

    @Shishya With all due respect the most voted answer doesn’t solve this question in a direct manner. The question asks for git-rebase situation while the answer gives a flag for git-merge

    Dec 28, 2016 at 8:53

  • 7

    In case someone else made the same mistake, I got this error after accidentally using git pull [repo URL] instead of git clone [repo URL]

    – rsoren

    May 27, 2017 at 23:04

  • 5

    Possible duplicate of Allow merging unrelated histories in git rebase

    – vossad01

    Jun 17, 2017 at 18:07

  • 73

    A mess has been made here by the fact that the title doesn’t specify that this is in the context of a rebase, so your question is drawing in Googlers who are getting this error in different contexts and upvoting an answer that doesn’t actually apply to the question you’ve asked. It can’t be easily cleaned up now, so the incoherent Q&A pair will remain on the site and high in the Google search results forever. The moral of the story is that question titles matter!

    Jun 30, 2017 at 10:35


  • 4

    The best answer to this question can actually be found in this SO question. It is safer, more accurate, and better explained that the top answer here.

    Apr 27, 2018 at 22:04

1851

In my case, the error was just fatal: refusing to merge unrelated histories on every try, especially the first pull request after remotely adding a Git repository.

Using the --allow-unrelated-histories flag worked with a pull request in this way:

git pull origin branchname --allow-unrelated-histories

As per 2.9.0 release notesgit pull has been taught to pass the --allow-unrelated-histories option to underlying git merge

17

  • 351

    I always see this error if when I create a new Github repository with a README.md, then pull it to a local repository at the first time. So annoying.

    – Tien Do

    Dec 27, 2016 at 3:25

  • 59

    For new repos, first pulls, it’s typically better to start with a git clone.

    – Umbrella

    Feb 10, 2017 at 16:58

  • 3

    @PardeepJain Please see this github.com/git/git/blob/master/Documentation/RelNotes/…

    – Adil

    Jan 12, 2018 at 7:57

  • 4

    This stopped me for several hours, before I realized there had to be an obvious resolution for merging files like this if it occurs for default files – I’m glad I”m not the only one who has had this problem at least!

    – Zibbobz

    Dec 19, 2018 at 20:16

  • 3

    In my case it happened because I added license file at github. The command mentioned above (and below, they are the same) worked.

    – uudaddy

    Mar 16, 2019 at 20:09

702

Try the following command:

git pull origin master --allow-unrelated-histories

This should solve your problem.

4

  • 2

    how is this any better than the first answer?! stackoverflow.com/a/37938036/274502 should’ve been a comment or edit on it, to avoid redundancy and misinformation.

    – cregox

    Mar 31, 2021 at 4:43


  • 4

    cause it solves tl:dr

    – okandas

    Nov 19, 2021 at 18:36

  • @okandas good luck with that. glancing over some things will need more luck than most people would ever like to admit.

    – cregox

    Mar 16 at 12:17


  • This is the right solution

    – ZamaaN

    Jun 3 at 5:53