My .gitignore Trick for Drupal Using Multi-site

I'm always tweaking my Git setup in search of version control nirvana. One thing I've been doing over the past several months makes use of .gitignore and Drupal's multisite feature. The default .gitignore for Drupal 7 looks like this:

# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php

# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private

It wisely avoids committing the settings.php files to the repository. (Imagine having to explain how you made your database password publicly available on Github.) Say I was working on cleaver.ca with some other developers. My sites folder would look something like this:

sites
  + cleaver.ca
  |  + settings.php
  + default
     + files
        + ...

The settings for the production database are in sites/cleaver.ca/settings.php. The way that the multisite feature works is this: any visit to the site at http://cleaver.ca or http://www.cleaver.ca, or even http://super-secret-site.cleaver.ca will use the settings file sites/cleaver.ca/settings.php. It does simple pattern matching so that any URL ending in cleaver.ca will first look for settings in the directory of the same name.

My Trick

My trick is simple: add a new sites directory for my local development environment. This will allow separate settings for my development environment. I work on a local site "cleaver.dev" running on MAMP or Vagrant, so I add a directory sites/cleaver.dev. It would look like this:

sites
  + cleaver.ca
  |  + settings.php
  + default
  |  + files
  |     + ...
  + cleaver.dev
     + .gitignore
     + settings.php

The .gitignore file contains just one line:

*

IE. Git will ignore the folder itself and everything in it. This way, none of the other developers would need to know about cleaver.dev or any of my local settings.

Note

I used to name my development server something like cleaver.local. On OSX, some time around Lion, the .local suffix started having special meaning and could cause timeouts and delays in loading the page. I switched to .dev and saved two keystrokes every time.