Friday, May 8, 2009

Deployment branches with Git

When you deploy code to different machines often times you need to add little tweaks, such as adding or modifying configuration files.

If you use Git to manage your project you can create one deployment branch per server:

$ git clone git://my/project.git
$ cd project
$ git checkout -b $(hostname) origin/master

Then perform any changes you want and commit them.

When it's time to update the deployment run:

$ git pull --rebase

to rebase the branch against the new state of the upstream branch.

This will replay your per-machine changes on top of the new head revision, without needing to push them back into the main branch.

If you want to know what's going on before you actually pull, git remote update followed by git status will tell you what the state of the deployment branch compared to the upstream is.

Even nicer: we don't use origin/master as the remote branch, but rather some other stable branch, which we merge master into when we deploy. This simplifies the process of making minor fixes: you can do them on the stable branch and merge into master instead of doing them on the development branch and cherry picking into the stable branch.

No comments: