I have a git repo R1 with a submodule S1, and the latter has two branches, master and localpatches.
Let Q represent the source repo of the S1 submodule (in other words, Q is the argument that was given to the git submodule add ... that initially created the S1 submodule in R1).
For the purpose of this question you may assume that S1's localpatches branch is a direct descendant of its master branch.
Furthermore, you may ssume that all the commits in S1's master branch come from Q, while the commits in the range master..localpatches are present only in S1.
Now, I also have a separate git repo R2, that is completely distinct from R1. (By this I mean that R1 and R2 have no commits in common, they have different contributors, their associated work trees are completely different, etc.)
I would like to know the cleanest way to add a submodule S2 to R2 such that it is a replica of the S1 submodule of R1. In particular, (1) S2's source repo should also be Q; (2) the S2 should have two branches, master and localpatches; (3) the commits in the master (resp.localpatches) branches of S1 and S2 should be identical.
(Please correct me if I'm wrong, but the first of these requirements (namely, that S2's source repo should be Q) argues against creating S2 by just running git submodule add <S1's URL> in R2.)
(In case it matters, you may assume that the R1 repo is obsolescent/defunct. This means, in particular, that the issue of the future divergence between S1 and S2 is moot.)
localpatchesbranch toQ, maybe rename it. And then add your submodule from there?Qis owned by someone else, and they tend take months to consider, let alone accept, pull requests...