Sharing your development environment across branches
If you’re working on a project that bootstraps a development environment (using virtualenv or similar) it can be painful to bootstrap the environment for every bug/feature branch that you work on. There are lots of ways you can avoid this (local cache etc.), but if you’re using bzr to manage your branches, a single working directory for all your branches can solve the problem for you. Most bzr users will be familiar with this, but people new to bzr might benefit.
The one-time setup is pretty straight forward – create a repository with a local copy of trunk, and a branch of trunk for your new feature/bug:
$ cd dev/ $ bzr init-repo myproject $ cd myproject $ bzr branch lp:myproject trunk $ bzr branch trunk myfeaturex
From now on, you can simply `cd trunk && bzr pull` when you want to update your local trunk . Now we’ll create a light-weight checkout and bootstrap our environment there. I tend to call this directory ‘current_work’ but whatever works for you. Also, most of the projects I’m working on are using fabric for setting up the virtualenv and other tidbits, but replace that with your own bootstrap command:
$ bzr checkout --lightweight myfeaturex current_work $ cd current_work && fab bootstrap
Assuming everything went well, you now have your development environment setup and are ready to work on myfeaturex. Make changes, commit etc., push to launchpad – it’ll all be for your myfeaturex branch. But what if half-way through, you need to switch and work on an urgent bug? Easy: commit (or shelve) any changes you’ve got for your current branch, then:
$ cd .. $ bzr branch trunk criticalbugx $ cd current_work $ bzr switch ../criticalbugx 
Edit 2011-05-23: See Ricardo’s comment – the above 4 lines can be replaced by his two.
That’s it – your current_work directory now reflects the criticalbugx branch – and is already bootstrapped , you can work away, commit push etc., and then switch back to your original branch with:
$ bzr switch ../myfeaturex
If you’re working on large branches, once you’ve got the above workflow, you may want to try next keeping large features reviewable with bzr pipelines.
 It’s a good idea to never do any work in your trunk tree… always work in a branch of trunk.
 The ../ is not actually required, but when you’ve lots of branches with long names, it means you can tab-complete the branch name.
 Of course, if one of your branches changes any virtualenv requirements or similar, you’ll need to re-bootstrap, but that isn’t so often in practise. Or sometimes a new version of a dependency is released and you won’t get it until you rebootstrap.