Using Source Control for Advanced Web Development
If you’ve watched presentations by developers at large technology companies, you might notice that their development work flow and technology stack gets a lot of attention. You also might be surprised to learn that most of the companies use open source technology to deploy and manage their code.
Even if you work on a small team with a limited budget, there are a number of enterprise-caliber development features you can to add for to your technology stack fairly easily. Source control often is the foundation for these advanced development features.
Use Source Control
If you aren’t using source control (aka version control) for all your code, you are missing the single most important piece of an advanced development stack. In the end, it doesn’t matter if you are using Git, Subversion, Mercurial, et al as long as you are using something.
Using source control opens the gates for other things we’ll discuss in this article, as well as provides the benefit of a quick way to track (and fix) mistakes for the occasional “oops.” Once you start working with source control, it’s hard to imagine working without it.
Source Control the Easy Way
The easiest road to using source control is to use a hosted provider. Each provider will often offer additional services such as integration with bug tracking, time management, or deployment services. I use Beanstalk at my full-time employer. I couldn’t be happier with their service, but there are many other vendors out there. My short list includes:
- Assembla (Subversion or Git)
- Beanstalk (Subversion or Git)
- Bitbucket (Mercurial or Git)
- Github (Git only)
Include Common Code from Remote Repositories
If you’re responsible for multiple sites, it’s likely you have common code shared among them. A plugin here, a plugin there and before you know it, you’ve soon created some serious maintenance overhead.
For example, if you have a jQuery plugin that you use on every site you work on, you could simply put a copy of the common code in each repository, but that is far from ideal. A better alternative is to reference the common code from an external repository. The way this is done is by setting the
svn:externals property if you’re using Subversion or by adding a Git submodule if you’re using git. Both allow you to reference external projects and repositories inside of your project.
Working with svn:externals
The trick with
svn:externals is that you have to add the property to the folder one level up from the folder you want to bring into your project. Let’s say you want to bring the contents of
https://svn.example.com/trunk/scripts/common into your project to the
assets/scripts/common folder. In order to do this, you would need to first have the
assets/scripts folder in the repository. Then you would add the svn:externals property to the
assets/scripts folder via command line or a GUI like tortoiseSVN.
Working with Git Submodules
Automate Whenever Possible
Task automation is an indirect but awesome effect of using version control. This is probably the largest enterprise-caliber feature of an advanced development platform. My favorite use case for automation is deploying code to a server. Git, Mercurial, and Subversion all offer hooks that can be used to run code before or after the commit.
There are great resources about deploying code written and presented by some brilliant developers. Deploying code from version control is a much better solution than using FTP because it allows the development team to see what is deployed to each server as well as provide a mechanism for rolling back code to a prior version.
Craft-centric marketplace, Etsy has a wealth of information on their development blog about how they deploy code:
- Quantum of Deployment
- How does Etsy manage development and operations?
- Optimizing for Developer Happiness
Scott MacVicar mentions how Facebook uses git for source control but deploys from subversion in his presentation at PHP NW 2011.
Other Use Cases for Automation
Another example of automation is installing QA measures in the development workflow. If you wanted to run code through tools like JS Lint or run through unit tests, you could easily do this with pre-commit hooks.
In the modern development stack, version control is more than a way to keep track of code. It is an indispensible tool that is a catalyst for collaboration, deployment, and development.