3

I have a master repository with different subfolders. Each subfolder is brought into the repository as a "subtree" and exists as separate Git repository.

For example:

projectroot/my-subtree  (https://repo.com/my-subtree.git)
projectroot/my-subtree1 (https://repo.com/my-subtree1.git)
projectroot/my-subtree2 (https://repo.com/my-subtree2.git)

At this stage, what I have done for each of the subtreees is the following:

md my-subtree
git remote add -f my-subtree https://repo.com/my-subtree.git
git read-tree --prefix my-subtree -u my-subtree/master

Now, I would like to merge the local subtree with the updated code from the remote repository. When I try to do this using the following command, I get an error:

C:\project>git subtree pull --prefix=my-subtree my-subtree master
* branch              master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

I've tried using the --allow-unrelated-histories parameter, but it is not recognized my my version of git (2.14.3.windows.1).

I run the command like this:

C:\projects\>git subtree pull --prefix=my-subtree my-subtree master --allow-unrelated-histories

And get back this:error: unknown optionallow-unrelated-histories`

Can I solve the unrelated merge histories issue? Should I be doing something differently? Ideally I would like to be able to commit to projectroot as a normal Git project and push and pull changes from the (3) additional repositories as needed.

Brian
  • 6,910
  • 8
  • 44
  • 82
  • 1
    What output are you seeing that indicates `--allow-unrelated-histories` to not be recognized (and what exact command is causing such output)? That version of git should recognize the option as far as I can tell. – Mark Adelsberger Oct 31 '17 at 16:21
  • I've updated the question to show the command I am running, basically this: git subtree pull --prefix=my-subtree my-subtree master --allow-unrelated-histories – Brian Oct 31 '17 at 17:11
  • It looks like your `git subtree` front end does not know that it could pass this option along to `git merge`. (Whether it should *have* to, is another question altogether.) – torek Oct 31 '17 at 17:25
  • 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
  • It's possible,@MichaelFreidgeim though I haven't tested it. I think we realized subtrees weren't a great idea and started using a private package repository instead. – Brian Dec 11 '20 at 23:30

0 Answers0