Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to the same submodule twice

Tags:

git

I have two code libraries A and B and have started developing an application M. All three of these are stored in their own repository.

My problem is that I have a dependency such that A uses submodule B, but M uses both submodules A and B.

As far as I can tell I'll have two copies of the same submodule B for the same main project. But it would never make sense (in this setup) for them to be different, as they represent the same library in the same application.

Is there a way to work around this, so that when I work on M I have only one copy of A and B?

like image 342
DeadDog Avatar asked Oct 17 '13 10:10

DeadDog


People also ask

When should you use submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

Is git submodule a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

What does submodule sync do?

git submodule sync synchronizes all submodules while git submodule sync -- A synchronizes submodule "A" only. If --recursive is specified, this command will recurse into the registered submodules, and sync any nested submodules within.


1 Answers

M--/
   |-- A
   |   |-- B
   |
   |-- B

Just remove M/B submodule from M, and keep/use M/A/B.

The reasons:

  1. For A submodule(a independent repository), it must needs B for something.
  2. For M repository, you can teach it to use M/A/B.
like image 58
Yue Lin Ho Avatar answered Oct 06 '22 15:10

Yue Lin Ho