Git using subtree or submodule to manage external resources

Lukas Oppermann picture Lukas Oppermann · Oct 1, 2012 · Viewed 9.7k times · Source

I read much about how awful the git submodule is supposed to be, but I am not sure if that is just the groaning of people who feel it limits or if it has serious issues (especially concerning my use case).

I just want to include different repos into my repo like this

website/
 libs/
  js/
   fs-slides [external]
   fs-dialog [external]

and have to possibility to update those repos easily. As far as I understand there is no easy possibility of including just one file from a repo, right? (But that's okay.)

Should I use submodules for this?
Or are there any problems with it? Or is subtree much easier?

Answer

VonC picture VonC · Oct 1, 2012

Submodule is well-suited to your case, especially since you don't mind included those subrepos in their own subdirectory.

The main serious issue you could have using submodules is when updating them while having updates in progress, as described in "how exactly does git submodule work":

If you forget to set a branch when making commits in a submodules, said commits will be made on a detached HEAD, and those changes in progress will be lost at the next git submodule update (you can get them back through the reflog, if activated for your submodule repo).

Then, as Michael comments, and as I detail in the link above, you need to push the submodule to its own upstream before commit and pushing the parent repo (to avoid pushing unpublish submodule commits)