If you do not mind having multiple roots, you can do this (for each subproject):
- go to the subproject - we will call it the project 'foo'
- create the folder 'foo' there (we want everything contained in the project name)
git mv everything in the root directory in the root folder 'foo'- commit changes
Now in the main project (suppose you want to merge the "master" branches):
git remote add foo /path/to/foo/projectgit fetch foo- from the main branch of the do-
git merge foo:master project
This will create a merge commit, and from now on you will have everything related to the foo subproject in the foo folder in the main project. Before this confluence, you will be on either of two separate trees. For their stories, it makes no sense to mix, so this is a great way to set up a situation where two trees only connect at the place where you decided to combine them.
If you want the whole story of each subproject to merge into ...
This is a little trickier. The main idea is that you select the last commit from the main project and relocate the entire subproject to this point, so the whole subproject - that is, all its commits - grows from now on, d combine the head of the subproject back into the main project, possibly with - no-ff (no fast forward) so you can see the whole subproject in the commit bubble. This requires that the entire background of the subproject be in a subfolder of the project name (ie, "Foo" from the first section).
This will require a ton of manual work or something with git filter-branch , which I will have to work with for a while - I can’t think of it from my head. I assume this will be --tree-filter , and you will have to move everything that was not in the 'foo' folder to it for each commit. I don’t know how this processes branches and merges in the project, but I suspect that this works. I will not try to understand this in case you are ok with the first sentence with several roots (I think this is the best option for two).
If you don't mind multiple roots, but want to be able to send a back link up ...
If this is the case for subprojects - they are going to this repo forever and will never be able to see the light of day, none of the first two options will be in order. If you sometimes want to push you back, you should look into git submodules and subtrees .
Submodules essentially allow you to clone a repo into a specific folder in your project. Your project should only have tracks that need to be fixed. When you clone your main repo, the submodule folder will not exist. You can do this by running git submodule init to create a folder, and git submodule update to pull out all the files.
Fakes go further and read the entire subproject directly into a folder of your choice, mainly a repo. From now on, this folder exists just like any other folder in your project. Most of the magic here comes from merging a subtree, which allows you to make changes from a subproject without any history, while push changes are the other way around.
Given the option of all 3, I would prefer to use submodules or subtrees. This is a clean way to merge repositories together.