3

I am trying to add a subtree repo for another one. and use foo as the subtree repo and will be the directory.

After

git remote add st git@...git // st as subtree remote name

git subtree add --prefix=foo st develop

merge the subtree repo changes and use

git subtree pull --prefix=foo st develelop

since the two branch has different commit history, I met an error like:

fatal: refusing to merge unrelated histories

I found can add --squash to merge it, but when the st repo is under developing and I want to pull the changes, that seems need to add --squash each time and I don't want to do that.

I tried --allow-unrelated-histories, but git subtree seems can't know the option and show error, error: unknown option allow-unrelated-histories.

So, what is the right way to use git subtree? or any useful links that can help me know more about this will be great thanked

System: macOS

git version: 2.14.3

gy134340
  • 566
  • 5
  • 19
  • `git subtree add` should have merged the histories initially, so they no longer are unrelated. Can you verify if it did? Do you see after failed pull the head which it tried to merge? – max630 Apr 23 '18 at 05:14
  • @max630 thanks, seems after git subtree add with `--squash` option. we don't have the history any more, and have to use `--squash`. and I have do something like https://stackoverflow.com/a/49184933/5708287 – gy134340 Apr 23 '18 at 08:53
  • 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:36

0 Answers0