0

We have a main repo Core where we maintain libraries we use in many projects.

I was developing a library in a separate repo ErrorHandling, that I now want to permanently merge to Core, while keeping the commit history.

Is this possible?

Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109
  • Would this solution meet your needs? http://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories – David R. Longnecker Nov 22 '10 at 13:31
  • I thought it would first, but when I read about the solution (subtree merge) it doesn't seem like a permanent solution. To clarify: I want to merge, then **delete `ErrorHandling`**. – Markus Hedlund Nov 22 '10 at 13:34
  • possible duplicate of [How to import existing GIT repository into another?](http://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) – Jörg W Mittag Nov 22 '10 at 14:09
  • Not really a duplicate. And if it is, please explain how I can apply it to my problem – Markus Hedlund Nov 22 '10 at 14:43
  • Just did a [Subtree merge](http://progit.org/book/ch6-7.html), and sure enough, the directory is there. But the history doesn't seem to be merged, if I check `git log`. – Markus Hedlund Nov 22 '10 at 15:06
  • When you say you "want to permanently merge to Core", could you explain *where* in your repo it will merge? That is, is it going to look like Core/ErrorHandling, or something else? If the former, the solution presented in [How to import existing GIT repository into another](http://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) should work. – ebneter Nov 23 '10 at 01:54

1 Answers1

1

As commented, the subtree merge described in "How to import existing GIT repository into another?", based on GitHub article "Working with subtree merge", is a bit more complete than the basic subtree merge presented in the Git Book (mainly the git merge -s ours step).

git remote add errorHandlingRepo server:errorHandling.git
git fetch errorHandlingRepo 
git merge -s ours --no-commit errorHandlingRepo /master
git read-tree --prefix=errorHandling/ -u errorHandlingRepo/master
git commit -m "Imported errorHandling as a subtree."

You can track upstream changes like so:

 git pull -s subtree errorHandlingRepo master
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250