0
repository A (already existing)
examples\

repository B (already existing)
code\
test\

Trying to do the following - repo A should be a part of repo B. That its, repo B should look like -

repository B 
code\ 
test\ 
examples\ 

We would like to keep the two repositories separate. Users should be able to commit to them independently. If needed, repo A can be merged to repo B and vice-versa. I could think of sub modules but is there a different way to do this. Can I clone repo A within repo B, keep two repositories and do a push to the same remote. Use the branch names as repositories?

anushjay
  • 95
  • 2
  • 8

3 Answers3

2

No. Submodules is the only thing close to this, and that requires separate directories. There is only one .git directory (repository) in a directory, and that would contain either repoA or repoB, not both.

Paul Hicks
  • 13,289
  • 5
  • 51
  • 78
0

an easier (than submodules) way that retains a single .git is git subtree, but this also requires separate directories.

working in repo B

git remote add repoA url.for.A
git subtree add --prefix=examples/ repoA master

typing git subtree in a prompt gives a nice usage summary.

merging, pull and push are all possible. note that, although it isn't strictly necessary, a best practice is keep commits split between the subtree and main (don't mix commits to path examples/ with those to the other two) so that the commit log still makes sense.

to quote the help from git subtree:

[TIP]
In order to keep your commit messages clean, we recommend that
people split their commits between the subtrees and the main
project as much as possible.  That is, if you make a change that
affects both the library and the main application, commit it in
two pieces.  That way, when you split the library commits out
later, their descriptions will still make sense.  But if this
isn't important to you, it's not *necessary*.  git subtree will
simply leave out the non-library-related parts of the commit
when it splits it out into the subproject later.
jaimedash
  • 2,683
  • 17
  • 30
  • Thank you. This looks like it might work for me. Before I go ahead can you please elaborate on keeping commits path separate. I don't completely get it. Thanks ! – anushjay May 10 '16 at 15:04
  • Thanks for asking. It's more of a recommendation than a must do. Clarified and added a reference – jaimedash May 10 '16 at 15:45
0

You can also look into git-repo tool to keep the repositories split and then have them moved in the correct locations post-download. The manifest format is available here.

Serban Constantin
  • 3,316
  • 1
  • 18
  • 20