Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency management in git repositories (using submodules) [closed]

I have a rather big project with lots of dependencies. The project is stored in a git repository and the dependencies are stored in dedicated git repositories linked as submodules. The dependencies can have further dependencies (again, using git submodules).

This works well. However, if two dependencies required both a third dependency I run into trouble on updates.

A dependency graph looks like this:

[Main Repo]
  |
  |-- [ModuleA]
  |       |
  |       \-- [ModuleC]
  |
  \-- [ModuleB]
          |
          \-- [ModuleC]

Right now I update the submodule pointer in ModuleA and ModuleB. This way both modules remain self contained. However, this is a lot of work.

How is this problem usually solved in bigger projects? I am looking for best practices to approach this kind of problem.

Thanks!

like image 494
Lars Schneider Avatar asked Nov 21 '13 11:11

Lars Schneider


People also ask

Should I use Git submodules to manage external dependencies?

In these situations you can use git submodules to manually manage external dependencies. This guide discusses the pros/cons of dependency management with git submodules as well as some alternative approaches to consider to avoid the use of submodules.

How do I use Git submodules in my repository?

You can use the following commands to use Git submodules in your repositories. Clone a repository and load submodules. To clone a repository containing submodules: $ git clone--recursive < URL to Git repo > If you have already cloned a repository and want to load its submodules: $ git submodule update --init. If there are nested submodules:

How do you manage your dependencies without Git?

First choice: Use an appropriate build/dependency tool instead of git A dependency management tool is my current recommended way forward to handle the growing pains and the build times of sizeable projects. Keep your modules separated in individual repositories and manage their interdependency using a tool built for the job.

What is a sub module in Git?

Git submodules. Git submodules are a feature of the Git SCM that allow you to include the contents of one repository within another by simply specifying the referenced repository location. This provides a mechanism of including an external library’s source into an application’s source tree.


Video Answer


1 Answers

In bigger project, what you want is keep all your dependencies on one level.

That doesn't mean that ModuleA and ModuleB don't keep their own dependency to ModuleC.

That means your current main parent repo include a dependency on ModuleC, which acts as the referent version for C.
That also allows you to detect when a dependency has to be overridden as, in your case, for one of your two submodules: the dependency to ModuleC for ModuleA or ModuleB will have to be overridden by the one to ModuleC from your main Repo.

like image 100
VonC Avatar answered Oct 17 '22 20:10

VonC