participant participant - 1 year ago 57
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.

Answer Source

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download