Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git nested submodules and dependencies

Let's say I have four projects named Core, A, B, Super. The dependency tree is like this:

Super ---> Core        |-> A -> Core        |-> B -> Core 

I want each project to be stand-alone, that is, I want to be able to check-out and compile each project on its own (each with its dependencies of course).

I thought about mapping each project to a repository and then referring dependencies with submodules, but I see the following issues with that approach:

  1. When checking out Super with all its dependencies, I'd end up with three copies of Core.
  2. Since submodules are fully independent, each of these three copies could be pointing to different revisions of Core and that would be a mess.

So... Am I missing something? Did I misunderstand git submodules or misusing them? Is there any other solution to this problem (other than resorting to binary dependencies)?

like image 772
Mauricio Scheffer Avatar asked Sep 14 '09 02:09

Mauricio Scheffer


People also ask

Why you should not use git submodules?

This is because of some major drawbacks around git submodules, such as being locked to a specific version of the outer repo, the lacking of effective merge management, and the general notion that the Git repository itself doesn't really know it's now a multi-module repository.

Can I have nested git repositories?

Git allows you to include other Git repositories called submodules into a repository. This allows you to track changes in several repositories via a central one. Submodules are Git repositories nested inside a parent Git repository at a specific path in the parent repository's working directory.

When should I use git 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.

What are git submodules?

A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.


1 Answers

You just discovered the lack of overridden dependencies with Git submodules:

If Super depends on Core, its dependency of Core should "override" the ones A and B have with Core.

The only way to emulate that would be to create your Super project the way you did,
and to remove the sub-module Core of A and B.
(meaning Super depends now on A' and B', A' being A without Core, B' being B without Core)

like image 70
VonC Avatar answered Oct 11 '22 15:10

VonC