Home » Posts tagged "submodules"

How Git made my day with cloning, branching and submodules

So today at work I started working on a website that’s basically a clone of another one. The website to clone has a rather old code base but a fully working control panel with order processing, payment reminders, CRM and more. As the code base for the website itself was way too old I decided that that part should be newly written. Nothing fancy, just loading a few things from a database and displaying it.

The control panel on the other hand has to stay updated for both websites. Feature wise they should stay similar and bugs found in one of the control panels should be fixed in the other. So why not generalize the control panel and make them identically the same? Well, thinking ahead, the target group of both websites is different so there are always going to be a couple of specific features not needed for the other target group.

Before I’ll tell what I did to make this possible I’ll explain the current setup of the first site (the original website being “cloned”).

The original Git repository contained a directory called admin. I cloned the repository to strip out everything besides the admin directory with git filter-branch. I then added this new repository as a submodule.

The new website is, of course, also a Git repository. Since I need the control panel for this website as well I could add a submodule that points to the original Git repository. But that would severely hinder the process of modifying it for the new website. So instead I cloned the control panel repository. In this clone I maintain a branch for the new website. The new website has a submodule that points to this branch.

The benefits that’s giving me this is that I can make all the modifications I want, commit them to the branch created for this. Any updates that should be applied to the other site as well can be cherry picked to the master branch. When done I let the main repository (the one I filtered out of the original website) pull the changes back.

All in all this might sound a bit complicated, but it isn’t really. Thanks to Git I can keep both control panels up to date and safe without too much worries. Thank you Git!