Reputation: 8182
Say I have a project A
that makes use of another project B
.
To that end, there's a subfolder in the git repository of A
into which B
has been cloned.
Now, the simplest way to sync that folder to A's
repo would probably be to just add that folder and everything in it to A's
index and be done with it.
As I have no experience with such nested git structures, I do wonder if that's a smart thing to do, though. Do I risk anything by doing it that way and what are the alternatives?
Upvotes: 0
Views: 2460
Reputation: 8885
I would like to recommend: subtree merging because it's easier to maintain, as @kowsky mentioned, when your project changes often.
You just need to create each repository in the normal way. While in your "collector" repository, you may merge another repository as a sub-directory of your "collector" directory. To do that just run these commands:
$ git remote add -f AnotherRepo /path/to/that/repo
$ git merge -s ours --no-commit AnotherRepo/master
$ git read-tree --prefix=AnyDirectoryToPutItIn/ -u AnotherRepo/master
$ git commit -m "Merge AnotherRepo project as subdirectory"`
Then, to pull the AnotherRepo
into your "collector" repository (or to update it), use the sub-tree merge strategy:
$ git pull -s subtree AnotherRepo master
This is the common way to do it and it works :-)
More about this way including comparing it with sub modules may be found in this git Git-Tools-Subtree-Merging
Upvotes: 3