The Beauty of Git Submodules

My helpful little bit for the day is about one of the best features of Git: submodules. Submodules allow you to create a repository which, for lack of an in-depth explanation, references a set of other repositories (i.e. submodules). In essence, this feature allows you to create a super-project that groups together a series of smaller related projects without having to put all of your code in a single repository. The implications of this are massive!

For instance, in my current project, I have 8 separate repositories housing 8 related but independent parts of my current research project. If I’m working on one of my libraries and need to roll back to an earlier commit, I don’t want to have to roll back commits containing work I did on other related libraries; hence, each library is in it’s own repository. However, when my boss wants to clone my work to allow another student to use some libraries I have written, he doesn’t want to have to clone and manage 8 different repositories just to see my code. Enter submodules… Using my super-project which references each of my other projects as submodules, my boss can clone my super-project and have git do the rest of the work for him to fetch the code in each of the submodules. Now my boss is happy, and my life is a bit simpler. It’s a beautiful thing.

For more information on submodules check out this informative blog post:

http://blog.jacius.info/2009/08/09/your-git-submodule-and-you/

And this reference info for submodules:

http://schacon.github.io/git/user-manual.html#submodules

Add a comment