{"thread":{"id":"52472","subject":"Merging two Git-Repositories","startedAt":"2019-12-17T09:28:39Z","lastAt":"2019-12-17T20:13:40Z","messageCount":4,"participants":["Steve Keller","Roger Gammans","Jared Tobin","Stephan Beyer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"388339","messageId":"trinity-c6dbf360-5abe-43df-8428-85514195a7a6-1576574916643@3c-app-gmx-bs62","threadId":"52472","inReplyTo":null,"subject":"Merging two Git-Repositories","fromName":"Steve Keller","fromEmail":"keller.steve@gmx.de","sentAt":"2019-12-17T09:28:36Z","receivedAt":"2019-12-17T09:28:39Z","isPatch":false,"sender":{"key":"keller.steve@gmx.de","avatar":null},"body":"Is it possible to merge one Git-Repository into another?  I have\ndeveloped two independent repositories A and B, and now I find that\nB should be part of A in new sub-directory, e.g. A/B.  I want to\nmove B into A while keeping the whole development history of B.\n\nHow can I do that?\n\nSteve\n\n"},{"id":"388340","messageId":"fd4bd9c49d7d4daf4275b19a9b5f7478f2e4e145.camel@gammascience.co.uk","threadId":"52472","inReplyTo":"trinity-c6dbf360-5abe-43df-8428-85514195a7a6-1576574916643@3c-app-gmx-bs62","subject":"Re: Merging two Git-Repositories","fromName":"Roger Gammans","fromEmail":"rgammans@gammascience.co.uk","sentAt":"2019-12-17T10:02:22Z","receivedAt":"2019-12-17T10:02:34Z","isPatch":false,"sender":{"key":"rgammans@gammascience.co.uk","avatar":null},"body":"On Tue, 2019-12-17 at 10:28 +0100, Steve Keller wrote:\n> Is it possible to merge one Git-Repository into another?  I have\n> developed two independent repositories A and B, and now I find that\n> B should be part of A in new sub-directory, e.g. A/B.  I want to\n> move B into A while keeping the whole development history of B.\n> \n> How can I do that?\n\nIt is possible bit isn't straightforward, at least not if you want to\ninterleave the commits.\n\nIf you don't want to interleave the commits, just rename everything (*)\nin B to B/*' and merge the repo with A's repo. Then you will have a the\nstructure you want going forward, all the history together; but if you\ncheck out a historic commit you will have to decide to check out on the\n'A' or 'B' branches.\n\nIf you do want to interleave the comits the best  found was  ( \nhttps://metacpan.org/pod/distribution/Git-FastExport/script/git-stitch-repo\nto merge the repos. (from https://github.com/book/Git-FastExport/ )\n\nI've got some updates (\nhttps://github.com/rgammans/Git-FastExport/tree/hintfiles ) to it when\nI did some work on this a couple of years ago but the it looks like the\nupstream has improved a little since then. My changes allow you to try\nto give it hints in case in make mistakes, on choosing the correct\nparent for a commit. The whole system worked pretty well except where\nthere were a lot a diverging/remerging branches.\n\nMy process was to write a shell script to actually drive the process,\nand tweak the script to improve the results iteratively.\n\nHope this helps a little.\n\n-- \nRoger Gammans <rgammans@gammascience.co.uk>\n\n"},{"id":"388351","messageId":"20191217110354.GA82154@castor","threadId":"52472","inReplyTo":"trinity-c6dbf360-5abe-43df-8428-85514195a7a6-1576574916643@3c-app-gmx-bs62","subject":"Re: Merging two Git-Repositories","fromName":"Jared Tobin","fromEmail":"jared@jtobin.io","sentAt":"2019-12-17T11:03:54Z","receivedAt":"2019-12-17T11:11:02Z","isPatch":false,"sender":{"key":"jared@jtobin.io","avatar":null},"body":"On Tue, Dec 17, 2019 at 10:28:36AM +0100, Steve Keller wrote:\n> Is it possible to merge one Git-Repository into another?  I have\n> developed two independent repositories A and B, and now I find that B\n> should be part of A in new sub-directory, e.g. A/B.  I want to move B\n> into A while keeping the whole development history of B.\n\nYou can accomplish this with git-subtree(1), for which IMO the intuition\nof \"exotic merge commit\" more or less suffices.\n\nAn example (from A):\n\n  git remote add B B_REMOTE_ADDRESS\n  git subtree add --prefix B B master\n\n-- jared\n"},{"id":"388402","messageId":"a909ac32-c94a-fb17-ca4d-13e6ea42cc34@gmx.net","threadId":"52472","inReplyTo":"trinity-c6dbf360-5abe-43df-8428-85514195a7a6-1576574916643@3c-app-gmx-bs62","subject":"Re: Merging two Git-Repositories","fromName":"Stephan Beyer","fromEmail":"s-beyer@gmx.net","sentAt":"2019-12-17T20:13:35Z","receivedAt":"2019-12-17T20:13:40Z","isPatch":false,"sender":{"key":"s-beyer@gmx.net","avatar":"https://avatars.githubusercontent.com/u/143889?v=4"},"body":"On 12/17/19 10:28 AM, Steve Keller wrote:\n> Is it possible to merge one Git-Repository into another?  I have\n> developed two independent repositories A and B, and now I find that\n> B should be part of A in new sub-directory, e.g. A/B.  I want to\n> move B into A while keeping the whole development history of B.\n\nIf I get you right, you want a simple merge of two branches with no\ncommon ancestors. Here's a line-by-line sh example with project A in\ndirectory A and project B in directory B, and B will be merged into a\nsubdirectory \"project-b\" in A:\n\n  # change to B's directory\n  cd B\n\n  # create the subdirectory where B's files will be in A\n  mkdir project-b\n\n  # move all files into project-b\n  git mv -k * project-b\n\n  # probably check if this worked for you\n  ls\n  git status\n\n  # commit\n  git commit -m \"Move all files into subdirectory for inclusion into A\"\n\n  # change to A's directory\n  cd ../A\n\n  # fetch and merge B into A\n  git pull --no-rebase --allow-unrelated-histories ../B\n  # ... change commit message to something more meaningful ...\n\nThat's it.\n\nIf B is public you might want to replace its last commit by some commit\nthat adds a note that further development is going on in A.\n\nStephan\n"}]}