20

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Lukas Oppermann
  • 2,918
  • 6
  • 47
  • 62

1 Answers1

11

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)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    When making commits in a submodule you should also remember to `git push`. Because if you don't a `git commit && git push` in your main repo, you're pushing a reference to a submodule commit which doesn't exist anywhere else. – Michael Oct 07 '12 at 21:12
  • @Michael good point. I have included it in the answer for more visibility. – VonC Oct 07 '12 at 21:16