Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodules workflow

In my project I need to use third party code, stored in several Git repositories. My project is also stored in (separate) Git repository. There are several people working with me on the main project, and I'm the maintainer.

In earlier projects I used to copy dependencies manually to the Git working tree, adding a little file specifying version I use.

Now this is rather uncomfortable since I need to update daily one of dependencies, and often contribute code to it myself, most of the time coupled with changes into the main project.

I've decided to try Git submodules to do the management. The more I try them, the more frustrated I become. It even seems that manual copy is, perhaps, better.

Here are some of my concerns:

  • We're no longer able to get consistent repository state with a single command (git checkout now needs git submodule update --init).
  • We're not able to use some of the Git tools properly (git archive is the most notable).
  • We're not able to see the status changes / diffs into submodules from the main project.
  • As I've just found in a hard way, git submodule does not work with --git-dir and --work-tree options, and require physical change of current directory to the "toplevel of the working tree".

It seems that in order to streamline our submodules workflow (that is one operation == one command) we have to write a rather thick wrapper around Git. This is sad.

Note that it is not an option to move away from Git or to merge subproject development entirely into the main project.

Perhaps I'm using git submodules in a wrong way? Is there any good tutorial on the workflow?

Please speak up even if you don't know the proper answer, but do share my concerns. :-)

like image 785
Alexander Gladysh Avatar asked Oct 20 '09 19:10

Alexander Gladysh


People also ask

Are git submodules 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.

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.

Does git pull pull submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

How do I clone a repository with submodules?

The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.


2 Answers

You may want to try git subtree (alt link) instead. I’ve had a lot of luck with it, using both remote repos and clean (untied to master history) branches in my project.

like image 109
Ben Stiglitz Avatar answered Oct 17 '22 17:10

Ben Stiglitz


A recent thread on the git mailing list includes a patch for how to get a consistent repository state with a single command. It basically calls git submodule update when changing branches.

http://thread.gmane.org/gmane.comp.version-control.git/130155/focus=130330

like image 6
Andreas Sæbjørnsen Avatar answered Oct 17 '22 18:10

Andreas Sæbjørnsen