Oblomov
Oblomov

Reputation: 9625

Git: Combining two independent repos to one without losing the history

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?

Upvotes: 0

Views: 158

Answers (2)

mity
mity

Reputation: 2349

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
    

Upvotes: 1

Mr. Em
Mr. Em

Reputation: 78

You can find a solution here.

Basically,

  1. make a new repo
  2. merge from one of your repos
  3. move files
  4. repeat

Upvotes: 1

Related Questions