I was looking for a solution to a problem I was having, and wanted to write up my notes on it.
The Setup
Tony and I have a codebase we’re working on (Monotask), that we’re currently deploying several times a day to our server at Slicehost. We’re also preparing a server at a new host (at Linode), as we’re going to transfer the whole app over to Linode. We use Git (and Github) to manage our code repository, and we use Capistrano to deploy our code onto the server.
The Problem
Apart from the deploy.rb script, the entire app is identical for the two servers, and I’d like to be able to make changes in the master branch and merge them in to our “linode” branch without overwriting the “linode” version of deploy.rb. I don’t anticipate adjusting the deploy.rb file much, but I did want to make sure that we’d never risk overwriting it with an alternate branch’s code.
The Solution
As described at Pro Git, all I did was create a file called .gitattributes in the parent folder of deploy.rb (the /config directory), and include a line in it: deploy.rb merge=ours. I included that in both the “linode” and the “master” branches.
The Result
Just as I wanted, each branch gets its own unique ‘deploy.rb’ file, with no threat of it being overwritten.
