Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git using subtree or submodule to manage external resources

Tags:

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?

like image 298
Lukas Oppermann Avatar asked Oct 01 '12 06:10

Lukas Oppermann


People also ask

Is subtree better than submodule git?

If there is an external repository you own and are likely to push code back to, use Git submodule since it is easier to push. If you have third-party code that you are unlikely to push to, use Git subtree since it is easier to pull.

When should I use git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

What does git subtree do?

git subtree lets you nest one repository inside another as a sub-directory. It is one of several ways Git projects can manage project dependencies. Management of a simple workflow is easy. Older version of Git are supported (even older than v1.

Why do we need git submodule?

Git submodules allow you to keep a git repository as a subdirectory of another git repository. Git submodules are simply a reference to another repository at a particular snapshot in time. Git submodules enable a Git repository to incorporate and track version history of external code.


Video Answer


1 Answers

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)

like image 74
VonC Avatar answered Oct 05 '22 22:10

VonC