Merge two Git repositories without breaking file history AND resolve conflicts

21 views Asked by At

I need to combine two Git repositories into a third, new repository. Each original repository should be placed in a separate subfolder within the new repository. For instance, if I have repositories A and B, the directory structure of the third repository should look like this:

/root
   /repoA
      ...
   /repoB
      ...

It's important to note that all branches from repositories A and B should be transferred to the third repository.

I've identified a couple of methods to accomplish this:

  1. Utilizing git subtree:

    • Initialize the third repository: git init
    • Add the remote for repository A: git remote add repoA repo_url
    • Integrate the subtree into a separate folder: git subtree add --prefix repoA/ repo_url master
    • Repeat this process for all branches.
  2. Employing a script. For a more detailed explanation, you can refer to the verified answer in this question.

However, I'm encountering issues when attempting to merge branches in the third repository. For instance, if I try to merge the master branch into branchA, a significant number of conflicts arise, which do not occur when merging master into branchA in repository A or B.

0

There are 0 answers