21 comments

  • mmastrac10 hours ago
    Every time I end up using repos with submodules, I&#x27;m stuck in the submodule unwedging dance at some point. It&#x27;s just not worth it. Either it&#x27;s stuck with changes that accidentally snuck into the subtree (rm -rf and submodule init&#x2F;update), the commit is bad and git can&#x27;t update to it somehow (maybe it&#x27;s not a tag and can&#x27;t be fetched? usually gets fixed with rm -rf and submodule init&#x2F;update), or maybe it&#x27;s just when I switched branches and it&#x27;s left in a dirty state because... reasons.<p>Git is elegant is so many ways, but submodules are the broken, ugly stepchild of the beauty that git is.<p>I suspect it&#x27;s not the idea of submodules, but the terrible, terrible command interface to them and how badly they work with the rest of the system.
    • crossroadsguy10 hours ago
      Having used few “lesser” VCSes I am not so sure I’d call Git elegant. It just became famous and defacto VCS of the Internet - a lot of that credit must go to Github (which also was and is used a lot by comps and teams). Something like Markdown — one day everyone and their kittens were just using it which is not necessarily not a compliment.<p>I had created 2-3 char git submodule related aliases. Git submodule exists because a better alternative isn’t available (which gives us same behaviour or close to it).
      • nine_k9 hours ago
        As a side note: git won because <i>at the time</i> all other VCSes were either functionally worse (lice RCS or Subversion), or were good but required a paid license (like Perforce or BitKeeper), or were too slow to for larger projects like Linux (Mercurial).<p>More advanced things were created since then, like Fossil or Pijul. But the network effects make git predominant now.
        • cassianoleal5 hours ago
          &gt; But the network effects make git predominant now.<p>That and the fact that it&#x27;s... well, it&#x27;s a good system - if perhaps not with the best UX.<p>It works well for pretty much everyone who cares to learn the basics, and then you can evolve from there with more practice. Which is probably true of any system.
          • nine_k4 hours ago
            Indeed, git is pretty good internally, despite the clunkiness of the CLI.<p>But, say, Mercurial is also pretty good in many aspects. It used to be rather popular, but its popularity is waning, and not because of some kind of technical inferiority.
            • cassianoleal22 minutes ago
              According to the post I originally responded to:<p>&gt; or were too slow to for larger projects like Linux (Mercurial).<p>So it seems like there were technical reasons for Git vs. Mercurial. I don&#x27;t really know and having never used Mercurial, I couldn&#x27;t comment on how good it is or how it compares with Git.<p>From what I read around, it&#x27;s mostly the UX that&#x27;s marginally better on the Mercurial side. This is the point where the network effect certainly has weight. If one offering is not better enough than the one people are used to, there is no compelling reason to learn something anew and move all existing projects over.<p>When there is great technical reason, people will move though and the network effect will start moving across. See the previous systems that were popular before Git: Subversion, CVS, ClearCase, etc. Those have mostly been phased out completely, except maybe for older projects that have them ingrained into their processes and technology.
        • petepete5 hours ago
          Git won because GitHub.
          • nine_k4 hours ago
            I&#x27;ve been on a number of projects which used git without GitHub. But of course GitHub like &quot;the default&quot; repository of open-source projects has done a lot to make git the default VCS.
          • hiatus4 hours ago
            Have you forgotten sourceforge?
            • rileymat21 hour ago
              Sourceforge was terrible by the time Github was ascending.
          • guappa2 hours ago
            github was a paid service only in the beginning. Which means few were using it.
  • gorgoiler9 hours ago
    Not only are they “a pain” but I see git submodules as the technical equivalent of a “Big Tent” political party trying to fit mutiple divergent factions into a single entity.<p>At some point someone in a submodule repo is going to go rogue and make something incompatible with the bigger picture. Psychologically, they’ve merged to their trunk so as far as they are concerned their change is complete. Task done, “mission accomplished”. Yet until it’s also in the parent repo’s trunk, it might as well still be on a branch.<p>In a monorepo, the rogue coder would instead still be on a branch. They’re done when their branch works <i>and</i> their change is merged (er, ff’d!) onto the one true main, not before.<p>None of this applies to FOSS projects. Those <i>are</i> Big Tents where political negotiations are constantly required to keep various democratically equal projects aligned.<p>In the corporate world though I am entirely happy with a one party state running a top down, planned economy of N year plans following CEO-Thought, and with a single repository.
    • friendzis6 hours ago
      In trunk based development libraries do break product code, yes, which is (and should be recognized this way) 100% intentional. The other alternative is leaf based development where you have dependency hell because you can&#x27;t force product code to update libraries.<p>Pick your poison - change management is not an easy topic.
  • jimmydoe10 hours ago
    I don&#x27;t get the opposition to submodule. imho it&#x27;s fine, there are limited options with it, so limited chance it may go wrong.<p>some suggested package manager, which imho is another layer of dependency, e.g. in Python, it always takes me some extra seconds to figure out which package manager I&#x27;m supposed to use, and it&#x27;s constantly evolving.<p>end of day it&#x27;s up to which one you are most familiar with.
    • dig13 hours ago
      My impression of this opposition (and hate) is that people don&#x27;t read the docs and expect submodules to bend to their vision of how submodules should work. Because of that, we have multiple similar but not the same &quot;submodule&quot; implementations: git-submodule, git-subtree, git-subrepo...
    • nobodywillobsrv6 hours ago
      I think one problem is that submodules are kind of over-kill in situations where what you really want is to have separate repos for various reasons but one way of pulling them all in at once. You could make a script with the origins etc but then you put than in a repo and then ...<p>I use them in my personal projects and have a sprawling mass of crazy. It &quot;works&quot; but it&#x27;s a pain and I have scripts to recursively crawl through and basically do &#x27;git pull&#x27; everywhere or &#x27;git push&#x27;.<p>So if you end up using submodules when you don&#x27;t really care about <i>versioning</i> the sub-repos, I think you end up feeling a bit of an idiot like me. But it&#x27;s a pain to reverse.
    • sshine6 hours ago
      Submodules are the feature you discover someone pulled in when things don&#x27;t work, and after a bit of digging, you realize it&#x27;s because the submodule wasn&#x27;t initialized, and it didn&#x27;t say so anywhere.<p>I suspect the opposition to submodules comes from the poor (manual) integration.<p>As someone suggested in another thread, they ought to auto-recurse by default.<p>But I don&#x27;t think that&#x27;s going to happen, either.<p>Maybe something like direnv where it tells you about the unloaded submodule once you enter the repository. Except that won&#x27;t work for IDEs.
    • sureIy4 hours ago
      Same here. I used it and set it up once and had no issues personally, but only after documenting how to deal with it exactly.<p>It&#x27;s just a rare feature so people don&#x27;t know how to deal with it, so they just hate it. Once you figure out the 5 commands you will need you&#x27;re golden.
  • impure7 hours ago
    I love submodules. It&#x27;s similar to using a package manager but allows you to modify the submodules&#x27; code much easier. And as already mentioned you need to use `git config --global submodule.recurse true`. This really should be the default.
    • IshKebab6 hours ago
      Submodules are <i>okay</i> in theory. But in practice the actual implementation is very buggy and incomplete. It&#x27;s relatively easy to get into a state where your .git directory is completely broken. Plenty of operations are unreliable to the point that they break CI. They don&#x27;t work with worktrees.<p>On top of that they are needlessly confusing. Why is there a .gitmodules file <i>and</i> hidden state inside the .git directory? Why aren&#x27;t they cloned by default? Many of the UX issues have only been fixed if you turn non-default options on (e.g. the display of diffs can be changed from useless &quot;submodules changed from commit 123 to 456&quot; to &quot;these commits have been added&#x2F;removed&quot;).<p>Just all-round they are a mediocre idea, implemented badly.
    • silasdavis5 hours ago
      Absent mindedly moving a submodule breaks everything. It was relatively recently there was even support via git mv.
  • CSMastermind58 minutes ago
    After running the platform org at a company that used submodules: never again.<p>There was not a week that went by without me having to unstick some team that had horribly managed to screw things up because of them or watch an engineer burn an entire day fighting with them or watch a new hire completely confused.<p>&quot;Well if everyone would just ...&quot;<p>Everyone is not going &quot;to just&quot;. If your system relies on everyone inherently having the same understanding of the world and behaving in the same way, then it&#x27;s a terrible system.
  • TekMol7 hours ago
    I like Git Submodules very much.<p>Are there any downsides to completely skip dependency managers of specific languages and just use submodules to handle dependencies?<p>I don&#x27;t mean code by 3rd parties. I mean the projects and libraries I write myself. I am tempted to try and handle my own code-reuse purely through git submodules. Would I encounter any problems?
    • leni5365 hours ago
      &gt; Are there any downsides to completely skip dependency managers of specific languages and just use submodules to handle dependencies?<p>Submodules suck once you encounter a diamond dependency problem.
      • MereInterest1 hour ago
        It doesn’t even need to be a diamond to have dependency problems. Suppose I have two dependencies, A and B. Dependency A also depends on B. Now I have two copies of B, one from my submodule and one from A’s submodule, and there’s no guarantee that these are compatible versions.
    • maleldil1 hour ago
      If your projects and libraries are public, your package manager will likely let you use Git references (usually commits&#x2F;branches&#x2F;tags) to define dependencies. I find that cleaner than submodules.
    • skinner9277 hours ago
      We used them for years for dependencies, but have instead moved to a monorepo because of how we want to do releases. We never had any issues while using submodules.
    • imp0cat5 hours ago
      I am not sure what exactly are you trying to achieve, but take a look at Meson Wraps.
  • cjfd3 hours ago
    This is the article I should have read when first trying to use git submodules. The two main facts &quot;a submodule is another git repository&quot; and &quot;a submudule is always pinned to a specific commit of the other git repository&quot; are the most important things to understand git submodules. Somehow all tutorials&#x2F;examples that I saw before show lots of git commands and their outputs but do not highlight the two basic facts so they actually do not help.
    • dmazin1 hour ago
      Hey, I wrote this article. Just wanted to really thank you for saying that. I also felt like &quot;why didn&#x27;t anyone tell me this&quot; so I wanted to share it :-)
    • blueflow2 hours ago
      Type `man 7 gitsubmodules` into your terminal.<p>Edit: typo&#x27;ed command
      • cjfd2 hours ago
        <p><pre><code> [cjfd@cjfdpc ~]$ man 7 gitmodules No manual entry for gitmodules in section 7</code></pre>
  • yig56 minutes ago
    For C++, I&#x27;ve started using FetchContent as a kind of distributed package manager. When I think about it, why is that better than git submodules?
  • ChrisMarshallNY4 hours ago
    I’ve used submodules a lot, and choose not to use them, anymore. They are just too much work. I now use package managers to accomplish pretty much the same thing.<p>One project that I wrote, used nested submodules. There was a specific reason for the nesting, as it was a layered system, and each layer had a very specific context and functional domain, and submodules helped enforce that.<p>The problem was, it made changes a <i>huge</i> pain. If I made changes in the deeper layers, I’d need to propagate the changes throughout the entire chain, above. I wrote a few bash scripts to handle that, but it was fairly kludgy, and quite brittle.<p>I ended up just folding it all into a monorepo.<p>The one feature that I’d <i>love</i> to see in git, is something that Microsoft SourceSafe could do. I call it “Virtual Repos.”<p>You could make a “repo” that was actually an amalgam of files that were references to files in other repos. Their state in the virtual repo reflected their state in their “home” repo, and changes made in the virtual repo would go out to their home repo.<p>It must be a nightmare to get right, though. I can see why it would not be implemented, but these could be used for a lot of the same things that submodules are used for.
    • arccy3 hours ago
      maybe sparse checkouts would be analogous to virtual repos?
      • ChrisMarshallNY3 hours ago
        They are similar. I remember cataloging the differences, once, but that was a long time ago.<p>I don’t think sparse checkouts let you “mix and match,” the way virtual repos did.<p>Think of the files in the virtual repo as “symlinks” to their originals, in other repos.<p>Other than that, SourceSafe was kind of a nightmare, and I don’t miss it.
  • hakanderyal8 hours ago
    Checkout git subrepo [0] if you also find working with submodules cumbersome.<p>It has a different set of trade offs and works without any problems or changes to your workflow if they fit. (Only thing it has problems is rebasing, under specific circumstances)<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;ingydotnet&#x2F;git-subrepo">https:&#x2F;&#x2F;github.com&#x2F;ingydotnet&#x2F;git-subrepo</a>
    • IshKebab6 hours ago
      It would be nice if they could say how it differs to git subtree. Any idea?
  • dboreham12 hours ago
    imho: do not use submodules. Only need to deal with them when working on someone else&#x27;s project where they didn&#x27;t know this rule.
    • dheera11 hours ago
      other than the command line UX of submodules being crap, i think they are actually a good system.
      • m46311 hours ago
        I think that&#x27;s the nature of git. goes double for lsf.<p>Git reminds me of C - important language, used everywhere, but has never evolved with respect to usability.<p>EDIT: hmm... actually &quot;git switch&quot; was more usable to me
      • Xelynega11 hours ago
        What is bad about them on the command line? If you understand git the only extra things you need are `git submodule update --init` and `git submodule add ...`
        • Izkata10 hours ago
          Add in &quot;--remote --recursive&quot; to the &quot;update&quot; command and you have the same thing as unpinned svn externals.
        • GauntletWizard11 hours ago
          The UX that sucks is around what happens if they are unclean&#x2F;how to update them. A checkout doesn&#x27;t recursively checkout the relevant submodules. This is the biggest pain point for most orgs I&#x27;ve worked at. It&#x27;s an easy setting to set (`git config --global submodule.recurse true`) but the fact that it&#x27;s not default hurts.<p>Most engineers have a poor understanding of Git. My university had a great history of version control course right at the dawn of the git era (In 2006! RIT really speedran it, standardizing on Git by the end of the year, but also including tutorials on RCS, CVS, and SVN and a brief foray into Perforce). Still, a ton of my classmates just didn&#x27;t get it.<p>The other major blocker is what to do with an unclean submodule repo; I honestly don&#x27;t remember what git does by default, because it&#x27;s bad. And most projects get unclean real quick. Makefile hygeine is not common, and for most of time most projects became unclean from a simple `make`. It&#x27;s better now, but not great.
          • Xelynega5 hours ago
            &gt; Makefile hygeine is not common, and for most of time most projects became unclean from a simple `make`.<p>If you&#x27;re checking generated files into git, submodules aren&#x27;t the problem imo.<p>I can see the frustration of modifying submodules files and trying to commit the main repo, but if you have to do that then it wasn&#x27;t supposed to be a submodule. That&#x27;s like complaining that modifying node_modules files doesn&#x27;t apply upstream to your dependencies.
          • glandium7 hours ago
            There are bad interactions with rebase too.
            • usr11065 hours ago
              I have gotten rid of those by the rule: If a commit update updates a submodule, it must not update anything else. (Yes, this can violate the general rule that nothing needs to be added to a commit to be complete. But updating submodules has been worth the exception in my experience.)
  • AceJohnny211 hours ago
    The very short of submodules is this:<p>Git&#x27;s data system has 3 (&amp; 1&#x2F;2) types of objects:<p>1. A blob, which is analogous to a file, and is referenced by the hash of its contents<p>2. A tree, which is analogous to a directory, which contains blobs and other trees, and maps them to names. It is referenced by the hash of its contents.<p>3. A commit, which contains One (1) tree (the top-level of your repo), a reference to one (or more, for a merge) parent commit, and miscellaneous metadata like the author and the commit message. It is referenced by, you guessed it, the hash of its contents! (annotated tags are commit objects)<p>3.5. References, which are analogous to symlinks to commits. Branches and lightweight (non-annotated) tags are References.<p>Now, remember how a tree can contain a blobs or other trees? What if (<i>gasp</i>) you put a <i>commit</i> object in them!? That&#x27;s essentially what a submodule is.<p>That&#x27;s why a submodule is always included _at a particular commit of it_. That&#x27;s why there&#x27;s all sorts of complicated support machinery to make &quot;a commit object inside a tree object&quot; make sense.
    • IshKebab5 hours ago
      &gt; a submodule is always included at a particular commit<p>Actually you can make a submodule track a branch instead of a specific commit. I&#x27;ve never seen anyone actually do that though and it seems like a bad idea. Though I did work for a while for a company that had written a custom tool that worked like that and we never ran into any problems due to it.
      • eru2 hours ago
        What&#x27;s the hash of a branch?
  • megamix7 hours ago
    Git - 100+ flags and commands when you only need 3-5.
    • bvrmn2 hours ago
      Actually it&#x27;s backwards. Git gives ability to manage and navigate commit graph on quite low level using a pair of commands: checkout and reset and fulfill any wild desires. While in other VCSs it&#x27;s a separate command per case.<p>Note: I think GIT UX is horrible and requires multiple years of practice to be comfortable with.
    • eru2 hours ago
      Most of the time, you only need a handful of commands, but there&#x27;s a long tail of niche situations, especially if you are using git for maintaining a large project like the Linux kernel.<p>Remember, git was designed and written for the kernel first and foremost.
  • vermilingua12 hours ago
    Can anyone speak to usecases for submodules that arent better served by your language’s package manager? Multi-language codebases, languages without appropriate package management perhaps?
    • nrclark7 hours ago
      Submodules are great for projects where your code depends on upstream Git repos that you don&#x27;t control and don&#x27;t want to vendor yourself.<p>I recently did an embedded Linux design that depended on 5 external repositories: one from Yocto, three from OpenEmbedded, and one from a CPU vendor. My own code just sat on the top of this set of repos.<p>Submodules made that design very simple. One repo with all of my code in it, and submodules for all external repos. All dependent repos were pinned before of how submodules work. Pins were easy to update when desired, and never move on their own.
      • maleldil1 hour ago
        Isn&#x27;t that because you didn&#x27;t have a good package manager to handle these? If you have a package manager that allows you to add packages from Git repos, why would you use submodules?
    • ajfriend11 hours ago
      We use a submodule in <a href="https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;h3-py">https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;h3-py</a> to wrap the core H3 library, which is written in C. Submodules seemed like a reasonable way to handle the dependency, and, at least for this use case, the approach hasn&#x27;t given me any problems.
    • c0balt12 hours ago
      The latter had been an issue for me in the past with some projects that just weren&#x27;t packaged for, e. G., python and had to be imported directly. It can also be helpful for non-packaged assets that are held in a separate git repository.
    • bschwindHN12 hours ago
      &gt; Multi-language codebases<p>This is where I use them. I have some Rust bindings to C++ code, and that C++ code lives in my repo as a submodule. Everyone seems to hate submodules I guess because of the surprising behavior described in the post, but for my use case they&#x27;ve been completely fine.
    • dirkt5 hours ago
      I have used them for OpenAPI specs shared between frontend and backend, and database schemas together with values for a test database in the pipeline.<p>Yes, you can also solve this with a monorepo...
      • eru2 hours ago
        You can use git subtree to convert between mono-repo and separate repos, without losing your history. You can even keep both styles up to date concurrently.
    • foooorsyth10 hours ago
      Two of the largest tech companies in the world, Google and Meta, had to roll custom VCS for their day to day engineering operations because git and git submodule were so unsuitable. The default pack file behavior of git is completely unsuitable for a rapidly releasing company with a monorepo. You <i>don’t</i> want or need the entire history — you just want a few recent commits. You <i>do</i> want some visibility into what your coworkers are up to so you can prevent merge conflicts before they happen (centralization is good!). You <i>probably</i> only need part of the tree, not the entire thing.<p>If you go back and watch Linus’ talk at Google regarding git, he’s basically describing (unknowingly) why Google needs to <i>not</i> use git for its day to day. Even on a smaller scale, Android (AOSP) had to create a meta tool for git called git-repo to handle its source tree. Git submodule failed there.
      • eru2 hours ago
        &gt; Two of the largest tech companies in the world, Google and Meta, had to roll custom VCS for their day to day engineering operations because git and git submodule were so unsuitable.<p>Where did you get that from? Sources?<p>Google rolled their own VCS, because Google is older than Git, and they needed something that works. Their custom VCS is a hacked up version of Perforce.<p>By the time Git came around, Google was already pretty much committed to their in-house custom tool, too many things relied on it.
      • jayd166 hours ago
        Don&#x27;t all your examples predate stable git-submodules?
    • cxr5 hours ago
      Every &quot;language package manager&quot; with a lock file format and requirements file, is an inferior, ad hoc, formally-specified, error-prone, incompatible reimplementation of half of Git.<p>Almost every use case for a package manager is better served by Git, whether you choose to use submodules or not. If you want to do version control, use the version control system, and stop trying to do an end-run around the way it works.<p>Previously:<p>&gt; <i>I&#x27;m happy to criticize NPM the tool. The whole thing is designed as a second, crummier version control system that lives in disharmony with and on top of your base-level version control system (so it can subvert it). It&#x27;s a terrible design.</i><p>&lt;<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=37604551">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=37604551</a>&gt;
      • eru2 hours ago
        Git knows nothing about eg semantic versioning, or how to resolve different requirements from different libraries that you want to use together.
        • cxr34 minutes ago
          Right.
  • abdullahkhalids8 hours ago
    I am running simulations with a rapidly evolving codebase. I have a separate repo with all the simulation code in it. I am want to tie each simulation with the git commit (of the main repo) at which it was run. Are git submodules the correct solution to this in any way?
    • banditelol1 hour ago
      I think you want something aling the line of dvc (github.com&#x2F;iterative&#x2F;dvc)
    • swinglock6 hours ago
      Perhaps. Tags might be fitting instead.
  • the_clarence4 hours ago
    Does Meta sapling git wrapper facilitates working with submodules?
  • 0x6942011 hours ago
    understanding submodules has not caused me to stop wishing that something in the vein of nix (in the sense of being able to provide a &quot;lockfile&quot; that transcends language-level package managers) becomes sufficiently commonplace that people would feel silly doing anything other than using whatever that turns out to be, or just directly vendoring if all else fails
  • vsskanth12 hours ago
    speaking of submodules, anyone here have experience with git subrepo ?
    • metadat11 hours ago
      Subrepos are non-standard and don&#x27;t offer any significant benefit compared to submodules.<p>Even still, submodules are also best avoided.
  • tonymet9 hours ago
    I recommend trying subtree. for many cases it does what you need . And the other consumers (developers, build systems) don&#x27;t need any special tooling.
    • eru2 hours ago
      Yes, that&#x27;s my default suggestion as well.<p>Git subtrees also let you move back and forth between multiple repos vs mono-repo without losing history. So you don&#x27;t need to solve that particular debate in your team.
  • pictur6 hours ago
    [dead]