3

Consider a project with the following structure

  • Root
    • submodule_a
      • common_submodule
    • submodule_b
      • common_submodule

is it possible to add submodule_a and submodule_b in a way that they share the common_submodule. That is, I want the tree to look more like this:

  • Root
    • submodule_a
    • submodule_b
    • common_submodule
user877329
  • 6,717
  • 8
  • 46
  • 88

1 Answers1

0

This is possible. The first step is to git clone the common_submodule so that it is placed next to your first level submodules submodule_a and submodule_b.

Now open your project in terminal and move in each of your submodules. Here you go on and add the cloned common_submodule folder as submodule:

git submodule add ../common_submodule

After you have done this in each of your first level submodules you've achieved what you have been looking for.

Note that you might fist need to delete the common_submodule in each of your first level submodules, before you re-add it again as described. There are plenty of StackOverflow questions that explain how to do that, e.g. this.

Kevin Katzke
  • 3,581
  • 3
  • 38
  • 47
  • Wouldn't this procedure remove `common_submodule` from `submodule_a` and `submodule_b`, so when any change to `submodule_a` or `submodule_b` is committed, these projects are no longer standalone? – user877329 Sep 10 '18 at 12:41