3

To include a few external git repositories in my "main" repository, there are a few options:

  • submodules
  • braid
  • subtree

The first seems to be advised against by basically everybody. The second and third I believe are implementations of the subtree pattern.

Is one better? Which should I use? Why? How can I choose between them?

Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
  • I'm trying to make the same decision, I've also got Piston: http://piston.rubyforge.org/ in the mix. – drye Dec 10 '10 at 18:38

1 Answers1

4
  • submodule is great to:

    • reference one specific commit of another repo (true equivalent of svn external with explicit revision numbers),
    • keep the two histories (the parent repo and the external repo) separate (as in a component-based approach).
  • subtree is great for including the history of one repo into another.

So if those few external repositories have no vocation to end up with all the tags and commit history of the main parent parent, use submodules.
Otherwise, subtree is fine.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It looks like submodule is the "default" way to do this now, and subtree is the correct way to do it in the near future. – Paul Biggar May 19 '12 at 23:49
  • 1
    @PaulBiggar well, they still are two different way to link together two repo, for two different purpose (loose coupling with submodules, tight coupling with subtree) – VonC May 19 '12 at 23:51
  • What about braid (also asked about in the question)? – jfritz42 Feb 12 '16 at 22:34
  • @jfritz42 Braid? this braid? (https://github.com/cristibalan/braid). It is obsolete (https://github.com/cristibalan/braid/issues/4). Plus vendoring in git is called submodule: you memorize a SHA1 of a nested repo (instead of actually versioning the full content of said nested git repo) – VonC Feb 12 '16 at 22:45
  • Haven't used Braid yet but it's 2016 and it's still kicking. The previous comment is out of date now -- that issue was eventually closed. – johncip Nov 10 '16 at 10:04
  • @johncip good point. I stll prefer submodules but for complete vendoring (ie copying sources in a subfolder), braid might be OK. – VonC Nov 10 '16 at 10:09
  • yeah. seems like braid uses subtrees under the hood. so it still comes down to what you said about loose or tight coupling. from what I've seen so far it seems like submodules are at their least painful when you're mostly locking to specific versions of the module instead of trying to commit to both projects at once. – johncip Nov 11 '16 at 00:16