7

I'm trying to pull from a remote into a folder in my repo. When using:

git subtree pull --prefix my-local/folder my-remote master

I'm getting the following error:

fatal: refusing to merge unrelated histories

I read in an other post that I can use the option --allow-unrelated-histories but when I do I get error: unknown option --allow-unrelated-histories (I put the option last)

I'm using git version 2.10.1 and Windows 10

Any help or ideas on how to move forward with this is greatly appreciated!

Community
  • 1
  • 1
Kolombiken
  • 71
  • 3
  • Does this answer your question? [git subtree error "fatal: refusing to merge unrelated histories"](https://stackoverflow.com/questions/39281079/git-subtree-error-fatal-refusing-to-merge-unrelated-histories) – Michael Freidgeim Nov 22 '20 at 03:37

2 Answers2

1

I had this same problem, I got it to work by adding the --squash option. This option merges the subtree changes as a single commit. I am not sure why this works but it obviously solves the history problem.

dataskills
  • 646
  • 7
  • 15
  • what do you mean by the --squash option? at what point in the script do you do that? using : git pull old-repo master --allow-unrelated-histories is getting the 'unknown option' error and putting --squash after pull or at the end is not working - my git version is 2.5.0 on windows 2010 – ASheppardWork May 28 '21 at 16:06
  • after some digging I found - I had to add these extra steps--- 1) git remote add old-repo 2) git subtree add --prefix= old-repo master --squash 3) git subtree pull --prefix= old-repo master --squash 4) git pull old master --allow-unrelated-histories – ASheppardWork May 28 '21 at 17:11
-1

Try sudo add-apt-repository ppa:git-core/ppa && sudo apt-get update then use --allow-unrelated-histories

Neha
  • 3,456
  • 3
  • 14
  • 26