11 Aug 2008

Rails and git submodules can play nice

I use git submodules to track plugins that I have under active development. This way, I can make changes to the main repository as well as the plugins with minimum fuss. There’s a great tutorial on working with submodules, which includes a couple of gotchas that may explain why submodules have got such a bad rep from some quarters.

Gotcha No. 1 — Always commit changes in your submodules before commiting your main repository

If you make any changes to a submodule, be sure to commit and publish these changes before you commit anything in the main repository, otherwise you and others will have issues trying to clone the repository.

Gotcha No 2 — Check you’re on a branch before making changes

If you are cloning a repo with a submodule and run git submodule init/update, be aware that the submodule has been checked out at a specific commit as apposed to the head of a branch meaning you have to checkout a branch before you make any changes.