0

I got two repos with the following folder structure:

> folder1
  >.git
  > file1
  > file2

> folder2
  >.git
  > file3
  > file4

Now I want to create a new repo combining the two formerly independent root folders under one common root:

> repo
   >.git
   > folder1
      > file1
      > file2
    > folder1
      > file3
      > file4

How would I do that in Git without losing the history of either formerly independent repository?

Oblomov
  • 8,953
  • 22
  • 60
  • 106
  • 1
    Possible duplicate of [How do you merge two Git repositories?](https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories) – phd Sep 20 '17 at 00:24

2 Answers2

1

You can find a solution here.

Basically,

  1. make a new repo
  2. merge from one of your repos
  3. move files
  4. repeat
Mr. Em
  • 78
  • 5
1

I guess something as follows should work:

  1. Adapt the repo folder1 to have the right internal structure.

    cd folder1
    mkdir folder1
    git mv file1 folder1/file1
    git mv file2 folder1/file2
    git commit -a
    
  2. And ditto for the repo folder2.

    cd folder2
    mkdir folder2
    git mv file3 folder2/file3
    git mv file4 folder2/file4
    git commit -a
    
  3. Pull one into the other one with git pull

    cd folder1  # the top one, not the one we have created in the 1st step.
    git pull /path/to/folder2
    

    Or, alternatively, merge both into a newly created repo.

    mkdir repo
    cd repo
    git init
    git pull /path/to/folder1
    git pull /path/to/folder2
    
mity
  • 2,299
  • 17
  • 20
  • I get "not something we can merge" when I try this with one of my existing repos. – Oblomov Sep 19 '17 at 17:06
  • Ooops. You are right. Forry for the mystification. `git merge` is just for branches in single repo. I now tried with `git pull` and it seems to work. I updated the answer. – mity Sep 19 '17 at 17:56