Search code examples
gitgit-submodules

Is there a way to add git submodule without nested submodule?


I have three repositories.

  • RepoCommon
  • RepoTn
  • RepoTh

RepoCommon is added as submodule to both RepoTn and RepoTh. Both RepoTn and RepoTh are two different repositories because earlier in the development it was recognized that those two are independent application. But now later in the development part we realized RepoTn is highly dependent on RepoTh.

As a solution I'm thinking of adding RepoTh as a submodule to RepoTn. But the one thing that bothers me is the "extra" RepoCommon inside RepoTh. If I do that it will essentially have the following structure:

  • RepoTn
    • RepoCommon
    • RepoTh
      • RepoCommon -> this is the part I'm trying to remove

I'm wondering if it's even possible to remove RepoCommon from RepoTh when I want to add it as a submodule to RepoTn.

Note: RepoTh needs to live on as it's own separate repository as well. Also, another reason I'm asking this because if I can remove/ignore the RepoCommon I can modify the project file to make sure system uses the correct RepoCommon folder. I am using Visual Studio 2019 if that makes any difference. Any other suggestion for a better solution is also welcome.


Solution

  • If possible, you should add an additional repository, which will record those dependencies:

    RepoTnParent
      RepoTn
      RepoTh
      RepoCommon
    

    That way, if you need to build RepoTn, you would load the RepoTnParent which will in turn load the right version RepoTn, RepoTh and RepoCommon.