Here at Liip we use Git for version control on almost all our projects. So this post is not about why we chose Git over any other VCSs but how we use it to develop Drupal projects.
The main challenge when using Git in Drupal is how to incorporate Drupal modules. You could decide to drop them directly in your base Git repository, as a first step it would be really easy. But you would then lose all their history, and maintenance would be quite painful: want to test a new branch or tag and then go back to the old situation? Possible, but if you have further commits on top of it, it could become quite tricky.
That’s where git submodules come in: using them allow you to leave each module in its own repository which has multiple avantages: you keep their history untouched, can easily change branch or tag and go back if needed, merge any new release, etc..
In Drupal 6 the setup was quite painful, as modules creators/maintainers were not using Git themselves. At Liip, we used to create Git repos and drop the files in. This means that you lose most of the submodules power but at least all modules can be tracked separately and any change would be Git versioned. But now with Drupal 7 it’s much easier: all modules are in Git already so all you have to do is point to their remote origin and start enjoying them! (see the resources at the end for more on the ‘how’ side).
If we need to make any change/fix on an external module we would clone it, create a new branch (or not, depending on the amount of changes), do the updates, add a new remote (either on github or on our own Git repository server), push the changes there and offer the Drupal module maintainer to review and possibly integrate the changes.
Your submodule is now pointing to another remote, so your co-workers will have to use the git ‘submodule sync’ command to update their copy.
Git submodules make it really easy to track modules’ lifecycle and is a key part of the way we do Drupal at Liip (along with Debian packages for deployment
and Drush+Features for scripting). And with Drupal move to Git you have no more excuse not to use them!
Want to get more into technical details? check our FOSSwiki