Bazaar

Bazaar

 




Wiki Tools

  • Find Page
  • Recent Changes
  • Page History
  • Attachments

Setting up one Working Directory to work with many Branches

This page explains how to set up a working directory to be used with multiple branches. This will be familiar to those who have used Git in the past and are migrating to Bazaar.

Background Information

Extracted from BzrVsGit > Directories are branches, not branch containers:

[...] it's true than many Git users like its approach and it does have benefits worth noting:

  • the one working tree can be used for multiple branches saving disk space
  • certain tasks like pulling and pushing a set of branches at the one time are easier.

Bazaar has solutions to both of these issues although they aren't necessarily well advertised. To use the one working tree for multiple branches, set up a shared repository with the --no-trees option together with a lightweight checkout. The switch command (within the bzrtools plugin before bzr v1.0, part of bzr itself thereafter) can be used to change which branch the working tree is tied to. To pull a set of branches at once, use the multi-pull command within bzrtools. There is no easy way to push a set of related branches at once currently in Bazaar - use the repo-push plug-in instead.

See also DraftSpecs/ColocatedBranches

Using the colo plugin

The colo plugin provides a few command to do easily what's described below. Check it out at https://launchpad.net/bzr-colo

What To Do

(All the extra cds are there to get you back into the directory where you started -- you aren't expected to actually type them.)

To get this going for a project named $FOO:

  1. Create a no-trees repository:
    bzr init-repo --no-trees $FOO-repo
  2. Branch the project into the repository.

    If you have existing branches for this project, push them into subdirectories of the repository. For instance, if you have just one at $FOO/, do something like:

    cd $FOO
    bzr push ../$FOO-repo/devel # devel is just a suggested branch name
    cd ..

    (It would probably be a good idea to make a temporary commit containing any working-tree changes first. You can later bzr uncommit it to restore their status as working-tree changes. This will probably not be necessary with 1.13, however -- see below.) If you don't have a branch yet, do:

    bzr branch url://to/upstream/$FOO $FOO-repo/devel
  3. Do a lightweight checkout. If you had a branch already, back it up:
    mv $FOO{,.backup}
    To do the checkout, just run:
    bzr checkout --lightweight $FOO-repo/devel $FOO

    Do not skip this step. If you instead just turn your branch into a heavyweight checkout with bzr bind, you will:

    • Run the risk of having your checkout lose synchronization with the underlying branch
    • Be stuck with just one each of parent branch and push target, rather than having one of each for every branch

    Since 1.13, this is even easier: you can just invoke bzr reconfigure --lightweight-checkout, possibly with the --bind-to option to say what branch it should be a checkout of initially.

  4. Make a feature branch
    cd $FOO
    bzr branch . ../$FOO-repo/feature1
    cd ..
    Note that this command uses the working tree path as a synonym for the checked-out branch -- yet another reason to use a lightweight checkout.
  5. Switch branches
    cd $FOO
    bzr switch ../$FOO-repo/{devel,feature1}
    cd ..

The last two steps can be simplified into one, actually:

  • cd $FOO
    bzr switch -b feature1

    [Again, the cd commands are kinda ridiculous here -- maybe I should use another way of indicating where each step is to be done?]