Using Git Subtree Instead of Submodule

Posted on Jan 9, 2015

Recently working on a hybrid mobile app project with a few partners, we were using Github to store a were faced with wanted to share our app code and our server-side API code in a single repository. We wanted to be able to work on the API and deploy it to a server as a webservice but somehow keep it separate from our primary app code. We did not want to deploy our app code to the server nor did we want to bundle the API when we ran the build service for our compiled app files.

Just Use a Submodule

No. I don’t want to. I find submodules to be a pain. Besides that, we wanted to use a single repo for this project.

Then we came across the concept of subtrees. Subtrees do similar things to submodules. They allow you to keep a subproject in your main project, but they do not require you to use any special files like .gitmodule nor do they require users of your repository to do anything special. It doesn’t need any special permissions and can accept commits, branches, or merges however you want. Users don’t even need to know they exist.

Why Bother?

Why not just use a subdirectory and include it in your project?

A fair questions. But subtrees give you more control of your history. Subtrees allow you to create a separate history of the project if you want to. You can extract the history of the subtree and publish it as a standalone project or git repository. The new repository will not include the history of the original project.

Submit a Comment

Your email address will not be published. Required fields are marked *