Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging two Git repositories

Tags:

git

I have a one git project with a file structure like this:

    Project_A/files...

I have another git project with a file structure like this:

    Project_B/
        Project_A/files...
        files...

Now I want to merge Project A into Project B and continue using Project B as the sole repository.

I tried using the subtree merge, but I got an error saying "Entry 'XXX' overlaps 'XXX'"

Is there a way to merge Project A into Project B and retain all of the commit histories?

Thanks in advance!

like image 614
dirtytofu Avatar asked Feb 10 '10 02:02

dirtytofu


2 Answers

You could do something like this:

In Project_A, make a new Project_A subdirectory and git mv everything into it, so Project_A now looks like

Project_A/
    Project_A/files...

Then, in Project_B:

git remote add project_A Project_A
git fetch project_A
git branch project_A project_A/master
git checkout -b merge_trial master
git merge project_A

... and fix as necessary on merge_trial (or lather, rinse, repeat until you get what you want regarding conflicts/overlaps).

I've actually done something exactly like this as part of an svn->git migration.

like image 91
ebneter Avatar answered Oct 06 '22 22:10

ebneter


If projectB already contains projectA as a submodule, you should:

  • first remove projectA as a submodule to projectB
  • then try a subtree merge

If projectA was not a submodule of projectB, I would recommend fetching projectA into projectB repo, and then use the graft technique to link the two commit lines together, while not dealing with all the merge conflicts a classical merge would have involved.

See question Git question: possible to merge two different by equal repositories?

like image 29
VonC Avatar answered Oct 07 '22 00:10

VonC