participant participant - 6 months ago 24
Git Question

Git: Two projects, each in a repo. Combine in new repo in sub-dirs with a single linear history

I do have a Repo1 and a Repo2 containing Project1 and Project2 respectively. Each repo with its own history:

Repo1 / Project1
history: A -> C -> G -> L

Repo2 / Project2
history: B -> F -> R

I would like to create a NewRepo which hosts NewProject. NewProject includes Project1 and Project2 as independent subdirectories. The history of both repos should be merged into a single linear history.

NewRepo / NewProject
|_ Project1
|_ Project2
history: A -> B -> C -> F -> G -> L -> R

Q Git HowTo needed.

I'm aware of the answers below but they don't solve my problem.


With git subtree it is as simple as that

cd NewRepo
git init
# commit something pointless to have one commit in NewRepo
git subtree add --prefix=Project1 path/to/Repo1 <branch>
git subtree add --prefix=Project2 path/to/Repo2 <branch>