monorepo VS. github submodules

10,763

Yes, there is a lot of discussion about submodules being good / evil, but I tend to think that some are using them wrong. Just like hitting a nail with a sledgehammer and not expecting any drawbacks, just because they have similar names.

A few things to consider when using them:

  • They are entirely isolated between them and between the superproject. There will be no detailed history in the superproject of the commits made in the submodule, just the ones that updated it.

  • When you make a commit on a submodule, you need to push it, because you're in another repo. If you don't and you go to the superproject to update the submodule, you will end up with a reference to a commit that was not pushed. And this will lead to even more problems and confusion.

These are examples of situations I found very often and people complain about them, but I don't consider these as cons, just things that we need to be aware of so we can decide if it suits our project or not.

We're using it in a project that has another one embedded, more like a module. They are both developed separately, and from time to time we update the module to a new version, or just keep it at a certain one for compatibility reasons. We don't need to know who is working on the module, or what they made, we just want to know when they released a new version / fixed something.

Maybe someone with more experience will share it, we sure need it.

Share:
10,763

Related videos on Youtube

Hammer
Author by

Hammer

Updated on October 14, 2022

Comments

  • Hammer
    Hammer over 1 year

    Our app is built in microservice architecture, one service one repo. We are exploring whether we should create a monorepo, as many companies are following this practice. There are plenty of discussions about the pros and cons for mono vs. many. If we want to find an alternative to allow us have some cons from both options, should we use git submodules to provide 'looks-alike' mono structure?

  • Hammer
    Hammer over 6 years
    Thanks for the sharing. Yes, we need to push inside of submodules first before moving up to the parent module to push... Another thing I find is the IDE(webstorm) fails to recognize and auto-switch to the branch I git checkout in the terminal at the submodule level, which could be very misleading...
  • Badea Mihai Florin
    Badea Mihai Florin over 6 years
    No problem. Regarding the IDE, if you go to Settings / Version Control, do you see the path to both repos, or just the parent? My PhpStorm seems to be aware of both.
  • Hammer
    Hammer over 6 years
    but when u open the terminal to go into the submodule to do a git checkout to another branch, then go back to the IDE again, navigate to that submodule folder, on the bottom right, are you seeing the new branch checkout? For my case, after I configure the VC setting, I can see all, but have to manual switching
  • Badea Mihai Florin
    Badea Mihai Florin over 6 years
    Yes, when going back to the IDE my working tree refreshes, it starts indexing and the current branch is switched correctly. I can only checkout the other branch. There is a yellow star that is always on master, but it doesn't seem to affect anything. I'm running version 2017.2.4, if it helps.