Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodule alternative?

I have a couple of working trees with some dependences. AFAIK, git submodule would enforce the following:

  • have a copy of each working tree (slave) in a subdirectory of each working tree using it (master)
  • the master repository duplicates all the information from slaves

I don't mind the repos getting bigger, but having the copies is quite unacceptable for me. It would force me to reorganize all the projects, so that the copy would get linked. Moreover, editing of a wrong file could easily happen leading to confusion.

I've got another idea:

  • Each master stores a list of all its slaves.
  • No other information in the master is required.
  • With each commit in master, a "snapshot-commit" in the slave gets created.
  • The "snapshot-commit" is a snapshot of the current state of the working tree, it ignores the current state of the index (I'm already using "snapshot-commits" before throwing away some uncommited changes).
  • The "snapshot-commits" get collected in a branch whose name is derived from the master's name. The commit message contains the hash of the master commit. (IMHO, this is better than flooding by thousands of tags.)
  • A checkout works as usual, unless recursion into slaves is required.

The only problems I can see are the following:

  • The commits in the slaves will accumulate, and never get deleted even when the master commits no longer exist.
  • Commits in the master are not self-containing, you could delete a commit referred in the master. But I see no chance it could happen by accident, so I can live with it.
  • I can't imagine, how other git command could support this. But again, I can live with it.

I'm asking if somebody already implemented it (or if it's a bad idea).

like image 416
maaartinus Avatar asked Jul 16 '11 02:07

maaartinus


People also ask

Is Git submodule a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

What are Git Subtrees?

A Git subtree is a replica of a Git repository that has been dragged into the main repository. A Git submodule is a reference to a particular commit in a different repository. Git subtrees, which were first introduced in Git 1.7. 11, help you make a copy of any repo into a subdirectory of another.

What is Git subproject?

A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.

What is Gitslave?

Gitslave is a value added supplement designed to accelerate performing identical git actions over all linked repositories and aside from one new file in the superproject, adjustments to . gitignore, and perhaps a few private config variables, does not otherwise affect your repositories.


2 Answers

I think this is a bad idea because it's strange and it will take you off the supported path for many things.

First a clarification: When using submodules, the 'master' (referencing) repo does not get appreciably bigger. It stores only a repository reference (URL, probably) and a commit ID. But that doesn't seem to be the sticking point here.

When dealing with a problem like this there are three basically 3 paths you can go down:

  1. Put everything in a single repository. Have you convinced yourself 10 times that you really need to separate things out? Remember that you can start in one repo and split things out later. Also remember that git merges actually work, so developer contention isn't that much of an issue.

  2. Use some external package management system. Git is NOT, and doesn't pretend to be, a package manager. Odds are good that the platform you're using has a package manager that supports more complex dependency situations. Maven, rubygems, npm, nuget... there are lots of them.

  3. Use submodules 'mounted' in subdirectories.

Basically, submodules should be your last choice when dealing with your own code. They're great for dealing with third party libraries, but end up being a royal pain for your own code. Add on top of that the complicated solution you're proposing, and it just won't be very fun to work in.

like image 192
Russell Mull Avatar answered Sep 24 '22 00:09

Russell Mull


I am not sure I am following you since a parent repo (your "master") only store a reference to the tight SHA1 of a submodule (the sub-repo checked out within the parent repo).
The size of the parent repo isn't affected at all.

The subtree merge strategy (better managed though git subtree) would increase the size of the parent repo, but that (subtree merge) isn't what you are talking about.

The other alternative to submodule would be git-slave (gits), which is a bit like you want to implement.

like image 37
VonC Avatar answered Sep 22 '22 00:09

VonC