Bazaar User Guide

Contents

1   Introduction

1.1   Introducing Bazaar

1.1.1   What is Bazaar?

Bazaar is a tool for helping people collaborate. It tracks the changes that you and other people make to a group of files - such as software source code - to give you snapshots of each stage of their evolution. Using that information, Bazaar can effortlessly merge your work with other people's.

Tools like Bazaar are called version control systems (VCS) and have long been popular with software developers. Bazaar's ease of use, flexibility and simple setup make it ideal not only for software developers but also for other groups who work together on files and documents, such as technical writers, web designers and translators.

This guide takes you through installing Bazaar and how to use it, whether on your own or with a team of other people. If you're already familiar with distributed version control and want to dive straight in, you may wish to skim this section and jump straight to Learning more.

1.1.2   A brief history of version control systems

Version control tools have been evolving for several decades now. In simple terms, there have been 4 generations of tools:

  1. file versioning tools, e.g. SCCS, RCS
  2. tree versioning tools - central style, e.g. CVS
  3. tree versioning tools - central style, take two, e.g. Subversion
  4. tree versioning tools - distributed style, e.g. Bazaar.

The design and implementation of Bazaar builds on the lessons learned from all the previous generations of tools. In particular, Bazaar cleanly supports both the central and the distributed version control models so you can change models as it makes sense, without needing to change tools.

1.1.3   Central vs distributed VCS

Many traditional VCS tools require a central server which provides the change history or repository for a tree of files. To work on the files, users need to connect to the server and checkout the files. This gives them a directory or working tree in which a person can make changes. To record or commit these changes, the user needs access to the central server and they need to ensure they have merged their work with the latest version stored before trying to commit. This approach is known as the centralized model.

The centralized model has proven useful over time but it can have some notable drawbacks. Firstly, a centralized VCS requires that one is able to connect to the server whenever one wants to do version control work. Secondly, the centralized model tightly links the act of snapshotting changes with the act of publishing those changes. This can be good in some circumstances but it has a negative influence on quality in others.

Distributed VCS tools let users and teams have multiple repositories rather than just a single central one. In Bazaar's case, the history is normally kept in the same place as the code that is being version controlled. This allows the user to commit their changes whenever it makes sense, even when offline. Network access is only required when publishing changes or when accessing changes in another location.

In fact, using distributed VCS tools wisely can have advantages well beyond the obvious one of disconnected operations for developers. Other advantages include:

  • easier for developers to create experimental branches
  • easier ad-hoc collaboration with peers
  • less time required on mechanical tasks - more time for creativity
  • increased release management flexibility through the use of "feature-wide" commits
  • trunk quality and stability can be kept higher, making everyone's job less stressful
  • in open source communities:
    • easier for non-core developers to create and maintain changes
    • easier for core developers to work with non-core developers and move them into the core
  • in companies, easier to work with distributed and outsourced teams.

For a detailed look at the advantages of distributed VCS tools over centralized VCS tools, see http://bazaar-vcs.org/BzrWhy.

1.1.4   Key features of Bazaar

While Bazaar is not the only distributed VCS tool around, it does have some notable features that make it an excellent choice for many teams and communities. A summary of these and comparisons with other VCS tools can be found on the Bazaar Wiki, http://bazaar-vcs.org.

Of the many features, one in particular is worth highlighting: Bazaar is completely free software written in Python. As a result, it is easy to contribute improvements. If you wish to get involved, please see http://bazaar-vcs.org/BzrSupport.

1.1.5   Learning more

This manual provides an easy to read introduction to Bazaar and how to use it effectively. It is recommended that all users read at least the rest of this chapter as it:

  • explains the core concepts users need to know
  • introduces some popular ways of using Bazaar to collaborate.

Chapters 2-6 provide a closer look at how to use Bazaar to complete various tasks. It is recommended that most users read these in first-to-last order shortly after starting to use Bazaar. Chapters 7 and beyond provide additional information including some recommended best practices. This material can be read when required and in any order.

If you are already familar with other version control tools, you may wish to get started quickly by reading the following documents:

In addition, the online help and Bazaar User Reference provide all the details on the commands and options available.

We hope you find this manual useful. If you have suggestions on how it or the rest of Bazaar's documentation can be improved, please contact us on the mailing list, bazaar@lists.canonical.com.

1.2   Core concepts

1.2.1   A simple user model

To use Bazaar you need to understand four core concepts:

  • Revision - a snapshot of the files you're working with.
  • Working tree - the directory containing your version-controlled files and sub-directories.
  • Branch - an ordered set of revisions that describe the history of a set of files.
  • Repository - a store of revisions.

Let's look at each in more detail.

1.2.2   Revision

A revision is a snapshot of the state of a tree of files and directories, including their content and shape. A revision also has some metadata associated with it, including:

  • Who committed it
  • When it was committed
  • A commit message
  • Parent revisions from which it was derived

Revisions are immutable and can be globally, uniquely identified by a revision-id. An example revision-id is:

pqm@pqm.ubuntu.com-20071129184101-u9506rihe4zbzyyz

While these identifiers are necessary for internal use and external tool integration, branch-specific revision numbers are the preferred interface for humans. Typical revision numbers are 1, 42 and 2977.1.59. See Specifying revisions in the appendices for a closer look at the numerous ways that revisions and ranges of revisions can be specified in Bazaar, and Understanding Revision Numbers for a more detailed description of revision numbering.

1.2.3   Working Tree

A working tree is a version-controlled directory holding files the user can edit. A working tree is associated with a branch.

Many commands use the working tree as their context, e.g. commit makes a new revision using the current content of files in the working tree.

1.2.4   Branch

In the simplest case, a branch is an ordered series of revisions. The last revision is known as the head.

Branches may split apart and be merged back together, forming a graph of revisions. Technically, the graph shows directed relationships (between parent and child revisions) and there are no loops, so you may hear some people refer to it as a directed acyclic graph or DAG.

If this name sounds scary, don't worry. The important things to remember are:

  • The primary line of development within the DAG is called the mainline, trunk, or simply the left hand side (LHS).
  • A branch might have other lines of development and if it does, these other lines of development begin at some point and end at another point.

1.2.5   Repository

A repository is simply a store of revisions. In the simplest case, each branch has its own repository. In other cases, it makes sense for branches to share a repository in order to optimize disk usage.

1.2.6   Putting the concepts together

Once you have grasped the concepts above, the various ways of using Bazaar should become easier to understand. The simplest way of using Bazaar is to use a standalone tree, which has a working tree, branch, and repository all in a single location. Other common scenarios include:

  • Shared repositories - working tree and branch are colocated, but the repository is in a higher level directory.
  • Lightweight checkouts - branch is stored is a different location to the working tree.

The best way to use Bazaar, however, depends on your needs. Let's take a look at some common workflows next.

1.3   Workflows

1.3.1   Bazaar is just a tool

Bazaar supports many different ways of working together. This means that you can start with one workflow and adapt it over time as circumstances change. There is no "one true way" that always makes sense and there never will be. This section provides a brief overview of some popular workflows supported by Bazaar.

Keep in mind that these workflow are just some examples of how Bazaar can be used. You may want to use a workflow not listed here, perhaps building on the ideas below.

1.3.2   Solo

Whether developing software, editing documents or changing configuration files, having an easy-to-use VCS tool can help. A single user can use this workflow effectively for managing projects where they are the only contributor.

images/workflows_single.png

Advantages of this workflow over not using version control at all include:

  • backup of old versions
  • rollback to an earlier state
  • tracking of history.

The key features of Bazaar appropriate for this workflow are low administration (no server setup) and ease of use.

1.3.3   Partner

Sometimes two people need to work together sharing changes as they go. This commonly starts off as a Solo workflow (see above) or a team-oriented workflow (see below). At some point, the second person takes a branch (copy including history) of what the first person has done. They can then work in parallel exchanging changes by merging when appropriate.

images/workflows_peer.png

Advantages over Solo are:

  • easier sharing of changes
  • each line of each text file can be attributed to a particular change including who changed it, when and why.

When implementing this workflow, Bazaar's advantages over CVS and Subversion include:

  • no server to setup
  • intelligent merging means merging multiple times isn't painful.

1.3.4   Centralized

Also known as lock-step, this is essentially the same as the workflow encouraged/enforced by CVS and Subversion. All developers work on the same branch (or branches). They run bzr update to get their checkout up-to-date, then bzr commit to publish their changes to the central location.

images/workflows_centralized.png

Subversion and CVS are good choices for implementing this workflow because they make it easy. Bazaar directly supports it as well while providing some important advantages over CVS and Subversion:

  • better branching and merging
  • better renaming support.

1.3.5   Centralized with local commits

This is essentially the same as the Centralized model, except that when developers are making a series of changes, they do commit --local or unbind their checkout. When it is complete, they commit their work to the shared mainline.

images/workflows_localcommit.png

Advantages over Centralized:

  • Can work offline, e.g. when disconnected during travel
  • Less chance for a bad commit to interfere with everyone else's work

Subversion and CVS do not support this model. Other distributed VCS tools can support it but do so less directly than Bazaar does.

1.3.6   Decentralized with shared mainline

In this workflow, each developer has their own branch or branches, plus commit rights to the main branch. They do their work in their personal branch, then merge it into the mainline when it is ready.

images/workflows_shared.png

Advantage over Centralized with local commits:

  • Easier organization of work - separate changes can be developed in their own branches
  • Developers can merge one another's personal branches when working on something together.

Subversion and CVS do not support this model. Other distributed VCS tools support it. Many features of Bazaar are good for this workflow including ease of use, shared repositories, integrated merging and rich metadata (including directory rename tracking).

1.3.7   Decentralized with human gatekeeper

In this workflow, each developer has their own branch or branches, plus read-only access to the main branch. One developer (the gatekeeper) has commit rights to the main branch. When a developer wants their work merged, they ask the gatekeeper to merge it. The gatekeeper does code review, and merges the work into the main branch if it meets the necessary standards.

images/workflows_gatekeeper.png

Advantage over Decentralized with shared mainline:

  • Code is always reviewed before it enters the mainline
  • Tighter control over when changes get incorporated into the mainline.

A companion tool of Bazaar's called Bundle Buggy can be very useful for tracking what changes are up for review, their status and reviewer comments.

1.3.8   Decentralized with automatic gatekeeper

In this workflow, each developer has their own branch or branches, plus read-only access to the mainline. A software gatekeeper has commit rights to the main branch. When a developer wants their work merged, they request another person to review it. Once it has passed review, either the original author or the reviewer asks the gatekeeper software to merge it, depending on team policies. The gatekeeper software does a merge, a compile, and runs the test suite. If and only if the code passes, it is merged into the mainline.

Note: As an alternative, the review step can be skipped and the author can submit the change to the automatic gatekeeper without it. (This is particularly appropriate when using practices such as Pair Programming that effectively promote just-in-time reviews instead of reviewing code as a separate step.)

images/workflows_pqm.png

Advantages over Decentralized with human gatekeeper:

  • Code is always tested before it enters the mainline (so the integrity of the mainline is higher)
  • Scales better as teams grow.

A companion tool of Bazaar's called Patch Queue Manager (PQM) can provide the automated gatekeeper capability.

1.3.9   Implementing a workflow

For an in-depth look at how to implement each of the workflows above, see chapters 3 to 6 in this manual. First though, chapter 2 explains some important pre-requisites including installation, general usage instructions and configuration tips.

2   Getting started

2.1   Installing Bazaar

2.1.1   Linux

Bazaar packages are available for most popular Linux distributions including Ubuntu/Debian, Red Hat and Gentoo. See http://bazaar-vcs.org/Download for the latest instructions.

2.1.2   Windows

For Windows users, an installer is available that includes the core Bazaar package together with necessary pre-requisites and some useful plug-ins. See http://bazaar-vcs.org/Download for the latest instructions.

Note: If you are running Cygwin on Windows, a Bazaar for Cygwin package is available and ought to be used instead of the Windows version.

2.1.3   Other operating systems

Beyond Linux and Windows, Bazaar packages are available for a large range of other operating systems include Mac OS X, FreeBSD and Solaris. See http://bazaar-vcs.org/Download for the latest instructions.

2.1.4   Installing from scratch

If you wish to install Bazaar from scratch rather than using a pre-built package, the steps are:

  1. If it is not installed already, install Python 2.4 or later.
  2. Download the bazaar-xxx.tar.gz file (where xxx is the version number) from http://bazaar-vcs.org/Download or from Launchpad (https://launchpad.net/~bzr/).
  3. Unpack the archive using tar, WinZip or equivalent.
  4. Put the created directory on your PATH.

To test the installation, try running the bzr command like this:

bzr version

This will display the version of Bazaar you have installed. If this doesn't work, please contact us via email or IRC so we can help you get things working.

2.1.5   Running the development version

You may wish to always be using the very latest development version of Bazaar. Note that this is not recommended for the majority of users as there is an increased risk of bugs. On the other hand, the development version is remarkably solid (thanks to the processes we follow) and running it makes it easier for you to send us changes for bugs and improvements. It also helps us by having more people testing the latest software.

Here are the steps to follow:

  1. Install Bazaar using one of the methods given above.

  2. Get a copy of the development version like this:

    bzr branch http://bazaar-vcs.org/bzr/bzr.dev
    
  3. Put the created directory (bzr.dev) on your PATH.

Advanced users may also wish to build the optional C extensions for greater speed. This can be done using make and requires pyrex and a C compiler. Please contact us on email or IRC if you need assistance with this.

2.1.6   Running multiple versions

It's easy to have multiple versions of Bazaar installed and to switch between them. To do this, simply provide the full pathname to the bzr command you wish to run. The relevant libraries will be automatically detected and used. Of course, if you do not provide a pathname, then the bzr used will be the one found on your system path as normal.

Note that this capability is particularly useful if you wish to run (or test) both the latest released version and the development version say.

2.2   Entering commands

2.2.1   User interfaces

There are numerous user interfaces available for Bazaar. The core package provides a command line tool called bzr and graphical user interfaces (GUIs) are available as plug-ins.

2.2.2   Using bzr

The syntax is:

bzr [global-options] command [options and arguments]

Global options affect how Bazaar operates and can appear either before or after command. Command specific options must appear after the command but may be given either before, during or after any command-specific arguments.

2.2.3   Common options

Some options are legal for all commands as shown below.

Short form Long form Description
-h --help get help
-v --verbose be more verbose
-q --quiet be more quiet

Quiet mode implies that only errors and warnings are displayed. This can be useful in scripts.

Note: Most commands typically only support one level of verbosity though that may change in the future. To ask for a higher level of verbosity, simply specify the -v option multiple times.

2.3   Understanding Revision Numbers

All revisions in the mainline of a branch will have a simple increasing integer. (First commit gets 1, 10th commit gets 10, etc.) This makes them fairly natural to use when you want to say "grab the 10th revision from my branch", or "fixed in revision 3050".

For revisions which have been merged into a branch, a dotted notation is used (eg, 3112.1.5). Dotted revision numbers have three numbers. The first number indicates what mainline revision change is derived from. The second number is the branch counter. There can be many branches derived from the same revision, so they all get a unique number. The third number is the number of revisions since the branch started. For example, 3112.1.5 is the first branch from revision 3112, the fifth revision on that branch.

Revisions are numbered in a stable way, such that if two branches have the same revision in their mainline, all revisions in the ancestry of that revision will have the same revision numbers. (So if Alice and Bob's branches agree on revision 10, they will agree on all revisions before that.) Future merges will not change revision numbers. However doing bzr pull can change revision numbers, because it changes the mainline revisions.

2.3.1   bzr versions < 1.2

Versions prior to bzr 1.2 used a slightly different algorithm. Some nested branches would get extra numbers (such as 1.1.1.1.1) rather than the simpler 3-number system.

2.4   Getting help

Bazaar comes with a built-in on-line help system. To see the list of topics, the command is:

bzr help

To see the list of commands, the command is:

bzr help commands

To get help on topic xxx or command xxx, the command is:

bzr help xxx

If you wish to search the help or read it as a larger document, the information is also available in the Bazaar User Reference.

2.5   Configuring Bazaar

2.5.1   Telling Bazaar about yourself

One function of a version control system is to keep track of who changed what. In a decentralized system, that requires an identifier for each author that is globally unique. Most people already have one of these: an email address. Bazaar is smart enough to automatically generate an email address by looking up your username and hostname. If you don't like the guess that Bazaar makes, then use the whoami command to set the identifier you want:

% bzr whoami "Your Name <email@example.com>"

If whoami is used without an argument, the current value is displayed.

2.5.2   Configuration files

Configuration files are located in $HOME/.bazaar on Linux/Unix and C:\Documents and Settings\<username>\Application Data\Bazaar\2.0 on Windows. There are three primary configuration files in this location:

  • bazaar.conf describes default configuration options,
  • locations.conf describes configuration information for specific branch locations,
  • authentication.conf describes credential information for remote servers.

Each branch can also contain a configuration file that sets values specific to that branch. This file is found at .bzr/branch/branch.conf within the branch. This file is visible to all users of a branch. If you wish to override one of the values for a branch with a setting that is specific to you, then you can do so in locations.conf.

Here is sample content of bazaar.conf after setting an email address using the whoami command:

[DEFAULT]
email = Your Name <email@example.com>

For further details on the syntax and configuration settings supported, see Configuration Settings in the Bazaar User Reference.

2.6   Using aliases

2.6.1   What are aliases?

Aliases are an easy way to create shortcuts for commonly-typed commands, or to set defaults for commands.

2.6.2   Defining aliases

Command aliases can be defined in the [ALIASES] section of your bazaar.conf file. Aliases start with the alias name, then an equal sign, then a command fragment. Here's an example ALIASES section:

[ALIASES]
recentlog=log -r-3..-1
ll=log --line -r-10..-1
commit=commit --strict
diff=diff --diff-options -p

Here are the explanations of the examples above:

  • The first alias makes a new recentlog command that shows the logs for the last three revisions
  • The ll alias shows the last 10 log entries in line format.
  • the commit alias sets the default for commit to refuse to commit if new files in the tree are not recognized.
  • the diff alias adds the coveted -p option to diff

2.6.3   Using the aliases

The aliases defined above would be used like so:

% bzr recentlog
% bzr ll
% bzr commit
% bzr diff

2.6.4   Rules for aliases

  • You can override a portion of the options given in an alias by specifying the new part on the command-line. For example, if you run lastlog -r-5.., you will only get five line-based log entries instead of 10. Note that all boolean options have an implicit inverse, so you can override the commit alias with commit --no-strict.
  • Aliases can override the standard behaviour of existing commands by giving an alias name that is the same as the orignal command. For example, default commit is changed with commit=commit --strict.
  • Aliases cannot refer to other aliases. In other words making a lastlog alias and referring to it with a ll alias will not work. This includes aliases that override standard commands.
  • Giving the --no-aliases option to the bzr command will tell it to ignore aliases for that run. For example, running bzr --no-aliases commit will perform a standard commit instead, not do a commit --strict.

2.7   Using plugins

2.7.1   What is a plugin?

A plugin is an external component for Bazaar that is typically made by third parties. A plugin is capable of augmenting Bazaar by adding new functionality. A plugin can also change current Bazaar behavior by replacing current functionality. Sample applications of plugins are:

  • overriding commands
  • adding new commands
  • providing additional network transports
  • customizing log output.

The sky is the limit for the customization that can be done through plugins. In fact, plugins often work as a way for developers to test new features for Bazaar prior to inclusion in the official codebase. Plugins are helpful at feature retirement time as well, e.g. deprecated file formats may one day be removed from the Bazaar core and be made available as a plugin instead.

Plugins are good for users, good for external developers and good for Bazaar itself.

2.7.2   Where to find plugins

We keep our list of plugins on the http://bazaar-vcs.org/BzrPlugins page.

2.7.3   How to install a plugin

Installing a plugin is very easy! If not already created, create a plugins directory under your Bazaar configuration directory, ~/.bazaar/ on Linux and C:\Documents and Settings\<username>\Application Data\Bazaar\2.0\ on Windows. Within this directory (referred to as $BZR_HOME below), each plugin is placed in its own subdirectory.

Plugins work particularly well with Bazaar branches. For example, to install the bzrtools plugins for your main user account on Linux, one can perform the following:

bzr branch http://panoramicfeedback.com/opensource/bzr/bzrtools
~/.bazaar/plugins/bzrtools

When installing plugins, the directories that you install them in must be valid python identifiers. This means that they can only contain certain characters, notably they cannot contain hyphens (-). Rather than installing bzr-gtk to $BZR_HOME/plugins/bzr-gtk, install it to $BZR_HOME/plugins/gtk.

2.7.4   Alternative plugin locations

If you have the necessary permissions, plugins can also be installed on a system-wide basis. Two locations are currently checked for plugins:

  1. the system location - bzrlib/plugins
  2. the personal location - $BZR_HOME/plugins.

On a Linux installation, these locations are typically /usr/lib/python2.4/site-packages/bzrlib/plugins/ and $HOME/.bazaar/plugins/. On a Windows installation, the system location might be C:\\Program Files\\Bazaar\\plugins while the personal location might be C:\Documents and Settings\<username>\Application Data\Bazaar\2.0\plugins.

One can additionally override the personal plugins location by setting the environment variable BZR_PLUGIN_PATH to a directory that contains plugins.

2.7.5   Listing the installed plugins

To do this, use the plugins command like this:

bzr plugins

The name, location and version of each plugin installed will be displayed.

New commands added by plugins can be seen by running bzr help commands. The commands provided by a plugin are shown followed by the name of the plugin in brackets.

2.7.6   Popular plugins

Here is a sample of some of the more popular plugins.

Category Name Description
GUI QBzr Qt-based GUI tools
GUI bzr-gtk GTK-based GUI tools
GUI bzr-eclipse Eclipse integration
General bzrtools misc. enhancements including shelf
General difftools external diff tool helper
General extmerge external merge tool helper
Integration bzr-svn use Subversion as a repository
Migration cvsps migrate CVS patch-sets

If you wish to write your own plugins, it is not difficult to do. See Writing a plugin in the appendices to get started.

3   Personal version control

3.1   Going solo

3.1.1   A personal productivity tool

Some tools are designed to make individuals productive (e.g. editors) while other tools (e.g. back-end services) are focussed on making teams or whole companies more productive. Version control tools have traditionally been in the latter camp.

One of the cool things about Bazaar is that it is so easy to setup that version control can now be treated as a personal productivity tool. If you wish to record changes to files for the purposes of checkpointing good known states or tracking history, it is now easy to do so. This chapter explains how.

3.1.2   The solo workflow

If you are creating your own masterpiece, whether that be a software project or a set of related documents, the typical workflow looks like this:

images/workflows_single.png

Even if you will always be working as part of a team, the tasks covered in this chapter will be the basis of what you'll be doing so it's a good place to start.

3.2   Starting a project

3.2.1   Putting an existing project under version control

If you already have a tree of source code (or directory of documents) you wish to put under version control, here are the commands to use:

cd my-stuff
bzr init
bzr add
bzr commit -m "Initial import"

bzr init creates a .bzr directory in the top level directory (my-stuff in the example above). Note that:

  • Bazaar has everything it needs in that directory - you do not need to setup a database, web server or special service to use it
  • Bazaar is polite enough to only create one .bzr in the directory given, not one in every subdirectory thereof.

bzr add then finds all the files and directories it thinks ought to be version controlled and registers them internally. bzr commit then records a snapshot of the content of these and records that information, together with a commit message.

More information on init, add and commit will be provided later. For now, the important thing to remember is the recipe above.

3.2.2   Starting a new project

If you are starting a project from scratch, you can also use the recipe above, after creating an empty directory first of course. For efficiency reasons that will be explored more in later chapters though, it is a good idea to create a repository for the project at the top level and to nest a main branch within it like this:

bzr init-repo my.repo
cd my.repo
bzr init my.main
cd my.main
hack, hack, hack
bzr add
bzr commit -m "Initial import"

Some users prefer a name like trunk or dev to main. Choose whichever name makes the most sense to you.

Note that the init-repo and init commands both take a path as an argument and will create that path if it doesn't already exist.

3.3   Controlling file registration

3.3.1   What does Bazaar track?

As explained earlier, bzr add finds and registers all the things in and under the current directory that Bazaar thinks ought to be version controlled. These things may be:

  • files
  • directories
  • symbolic links.

Bazaar has default rules for deciding which files are interesting and which ones are not. You can tune those rules as explained in Ignoring files below.

Unlike many other VCS tools, Bazaar tracks directories as first class items. As a consequence, empty directories are correctly supported - you don't need to create a dummy file inside a directory just to ensure it gets tracked and included in project exports.

For symbolic links, the value of the symbolic link is tracked, not the content of the thing the symbolic link is pointing to.

Note: Support for tracking projects-within-projects ("nested trees") is currently under development. Please contact the Bazaar developers if you are interested in helping develop or test this functionality.

3.3.2   Selective registration

In some cases, you may want or need to explicitly nominate the things to register rather than leave it up to Bazaar to find things. To do this, simply provide paths as arguments to the add command like this:

bzr add fileX dirY/

Adding a directory implicitly adds all interesting things underneath it.

3.3.3   Ignoring files

Many source trees contain some files that do not need to be versioned, such as editor backups, object or bytecode files, and built programs. You can simply not add them, but then they'll always crop up as unknown files. You can also tell Bazaar to ignore these files by adding them to a file called .bzrignore at the top of the tree.

This file contains a list of file wildcards (or "globs"), one per line. Typical contents are like this:

*.o
*~
*.tmp
*.py[co]

If a glob contains a slash, it is matched against the whole path from the top of the tree; otherwise it is matched against only the filename. So the previous example ignores files with extension .o in all subdirectories, but this example ignores only config.h at the top level and HTML files in doc/:

./config.h
doc/*.html

To get a list of which files are ignored and what pattern they matched, use bzr ignored:

% bzr ignored
config.h                 ./config.h
configure.in~            *~

Note that ignore patterns are only matched against non-versioned files, and control whether they are treated as "unknown" or "ignored". If a file is explicitly added, it remains versioned regardless of whether it matches an ignore pattern.

The .bzrignore file should normally be versioned, so that new copies of the branch see the same patterns:

% bzr add .bzrignore
% bzr commit -m "Add ignore patterns"

3.3.4   Global ignores

There are some ignored files which are not project specific, but more user specific. Things like editor temporary files, or personal temporary files. Rather than add these ignores to every project, bzr supports a global ignore file in ~/.bazaar/ignore2. It has the same syntax as the per-project ignore file.

[2]On Windows, the users configuration files can be found in the application data directory. So instead of ~/.bazaar/branch.conf the configuration file can be found as: C:\Documents and Settings\<username>\Application Data\Bazaar\2.0\branch.conf. The same is true for locations.conf, ignore, and the plugins directory.

3.4   Reviewing changes

3.4.1   Looking before you leap

Once you have completed some work, it's a good idea to review your changes prior to permanently recording it. This way, you can make sure you'll be committing what you intend to.

Two bzr commands are particularly useful here: status and diff.

3.4.2   bzr status

The status command tells you what changes have been made to the working directory since the last revision:

% bzr status
modified:
   foo

bzr status hides "boring" files that are either unchanged or ignored. The status command can optionally be given the name of some files or directories to check.

3.4.3   bzr diff

The diff command shows the full text of changes to all files as a standard unified diff. This can be piped through many programs such as ''patch'', ''diffstat'', ''filterdiff'' and ''colordiff'':

% bzr diff
=== added file 'hello.txt'
--- hello.txt   1970-01-01 00:00:00 +0000
+++ hello.txt   2005-10-18 14:23:29 +0000
@@ -0,0 +1,1 @@
+hello world

With the -r option, the tree is compared to an earlier revision, or the differences between two versions are shown:

% bzr diff -r 1000..          # everything since r1000
% bzr diff -r 1000..1100      # changes from 1000 to 1100

The --diff-options option causes bzr to run the external diff program, passing options. For example:

% bzr diff --diff-options --side-by-side foo

Some projects prefer patches to show a prefix at the start of the path for old and new files. The --prefix option can be used to provide such a prefix. As a shortcut, bzr diff -p1 produces a form that works with the command patch -p1.

3.5   Recording changes

3.5.1   bzr commit

When the working tree state is satisfactory, it can be committed to the branch, creating a new revision holding a snapshot of that state.

The commit command takes a message describing the changes in the revision. It also records your userid, the current time and timezone, and the inventory and contents of the tree. The commit message is specified by the -m or --message option. You can enter a multi-line commit message; in most shells you can enter this just by leaving the quotes open at the end of the line.

% bzr commit -m "added my first file"

You can also use the -F option to take the message from a file. Some people like to make notes for a commit message while they work, then review the diff to make sure they did what they said they did. (This file can also be useful when you pick up your work after a break.)

3.5.2   Message from an editor

If you use neither the -m nor the -F option then bzr will open an editor for you to enter a message. The editor to run is controlled by your $VISUAL or $EDITOR environment variable, which can be overridden by the editor setting in ~/.bazaar/bazaar.conf; $BZR_EDITOR will override either of the above mentioned editor options. If you quit the editor without making any changes, the commit will be cancelled.

The file that is opened in the editor contains a horizontal line. The part of the file below this line is included for information only, and will not form part of the commit message. Below the separator is shown the list of files that are changed in the commit. You should write your message above the line, and then save the file and exit.

If you would like to see the diff that will be committed as you edit the message you can use the --show-diff option to commit. This will include the diff in the editor when it is opened, below the separator and the information about the files that will be committed. This means that you can read it as you write the message, but the diff itself wont be seen in the commit message when you have finished. If you would like parts to be included in the message you can copy and paste them above the separator.

3.5.3   Selective commit

If you give file or directory names on the commit command line then only the changes to those files will be committed. For example:

% bzr commit -m "documentation fix" commit.py

By default bzr always commits all changes to the tree, even if run from a subdirectory. To commit from only the current directory down, use:

% bzr commit .

3.6   Browsing history

3.6.1   bzr log

The bzr log command shows a list of previous revisions.

As with bzr diff, bzr log supports the -r argument:

% bzr log -r 1000..          # Revision 1000 and everything after it
% bzr log -r ..1000          # Everything up to and including r1000
% bzr log -r 1000..1100      # changes from 1000 to 1100
% bzr log -r 1000            # The changes in only revision 1000

3.6.2   Viewing the mainline

As distributed VCS tools like Bazaar make merging much easier than it is in central VCS tools, the history of a branch may often show lines of development splitting off the mainline and merging back in at a later time. Technically, the relationship between the numerous revision nodes is known as a Directed Acyclic Graph or DAG for short.

In many cases though, you may only be interested in seeing the mainline for a branch, namely the primary line of development within the DAG. To do this, use the following command:

bzr log --short

If you do this commonly, you may even wish to create an alias for it as explained in Using aliases.

3.6.3   Tuning the output

The log command has several options that are useful for tuning the output. These include:

  • --forward presents the log in chronological order, i.e. the most recent revisions are displayed last.
  • the --limit option controls the maximum number of revisions displayed.

See the online help for the log command or the User Reference for more information on tuning the output.

3.6.4   Viewing the history for a file

It is often useful to filter the history so that it only applies to a given file. To do this, provide the filename to the log command like this:

bzr log foo.py

3.6.5   Viewing an old version of a file

To get the contents of a file at a given version, use the cat command like this:

bzr cat -r X file

where X is the revision identifier and file is the filename. This will send output to the standard output stream so you'll typically want to pipe the output through a viewing tool (like less or more) or redirect it like this:

bzr cat -r -2 foo.py | less
bzr car -r 1 foo.py > /tmp/foo-1st-version.py

3.6.6   Graphical history viewers

History browsing is one area where GUI tools really make life easier. Bazaar has numerous plug-ins that provide this capability including QBzr and bzr-gtk. See Using plugins for details on how to install these if they are not already installed.

To use the graphical viewer from QBzr:

bzr qlog

To use the graphical viewer from bzr-gtk:

bzr viz

viz is actually a built-in alias for visualize so use the longer command name if you prefer.

3.7   Releasing a project

3.7.1   Packaging a release

The export command is used to package a release, i.e. to take a copy of the files and directories in a branch and package them into a fresh directory or archive. For example, this command will package the last committed version into a tar.gz archive file:

bzr export ../releases/my-stuff-1.5.tar.gz

The export command uses the suffix of the archive file to work out the type of archive to create as shown below.

Supported formats Autodetected by extension
dir (none)
tar .tar
tbz2 .tar.bz2, .tbz2
tgz .tar.gz, .tgz
zip .zip

If you wish to package a different version to the last one, use the -r option. If you wish to tune the root directory inside the archive, use the --root option. See the online help or User Reference for further details on the options supported by export.

3.7.2   Tagging a release

Rather than remembering which version was used to package a release, it's useful to define a symbolic name for a version using the tag command like this:

bzr tag version-1-5

That tag can be be used later whenever a revision identifier is required, e.g.:

bzr diff -r tag:version-1-5

To see the list of tags defined in a branch, use the tags command.

3.8   Undoing mistakes

3.8.1   Mistakes happen

Bazaar has been designed to make it easy to recover from mistakes as explained below.

3.8.2   Dropping the revision history for a project

If you accidently put the wrong tree under version control, simply delete the .bzr directory.

3.8.3   Deregistering a file or directory

If you accidently register a file using add that you don't want version controlled, you can use the remove command to tell Bazaar to forget about it.

remove has been designed to Do the Safe Thing in that it will not delete a modified file. For example:

bzr add foo.html
(oops - didn't mean that)
bzr remove foo.html

This will complain about the file being modified or unknown. If you want to keep the file, use the --keep option. Alternatively, if you want to remove the file, use the --force option. For example:

bzr add foo.html
(oops - didn't mean that)
bzr remove --keep foo.html
(foo.html left on disk)

On the other hand, the TODO file is deregistered and removed from disk without complaint in this example:

bzr add TODO
bzr commit -m "added TODO"
(hack, hack, hack - but don't change TODO)
bzr remove TODO
(TODO file deleted)

Note: If you delete a file using your file manager, IDE or via an operating system command, the commit command will implicitly treat it as removed.

3.8.4   Undoing changes since the last commit

One of the reasons for using a version control tool is that it lets you easily checkpoint good tree states while working. If you decide that the changes you have made since the last commit ought to be thrown away, the command to use is revert like this:

bzr revert

As a precaution, it is good practice to use bzr status and bzr diff first to check that everything being thrown away really ought to be.

3.8.5   Undoing changes to a file since the last commit

If you want to undo changes to a particular file since the last commit but keep all the other changes in the tree, pass the filename as an argument to revert like this:

bzr revert foo.py

3.8.6   Undoing the last commit

If you make a commit and really didn't mean to, use the uncommit command to undo it like this:

bzr uncommit

Unlike revert, uncommit leaves the content of your working tree exactly as it is. That's really handy if you make a commit and accidently provide the wrong error message. For example:

bzr commit -m "Fix bug #11"
(damn - wrong bug number)
bzr uncommit
bzr commit -m "Fix bug #1"

Another common reason for undoing a commit is because you forgot to add one or more files. Some users like to alias commit to commit --strict so that commits fail if unknown files are found in the tree.

Note: While the merge command is not introduced until the next chapter, it is worth noting now that uncommit restores any pending merges. (Running bzr status after uncommit will show these.) merge can also be used to effectively undo just a selected commit earlier in history. For more information on merge, see Merging changes in the next chapter and the Bazaar User Reference.

3.8.7   Undoing multiple commits

You can use the -r option to undo several commits like this:

bzr uncommit -r -3

If your reason for doing this is that you really want to back out several changes, then be sure to remember that uncommit does not change your working tree: you'll probably need to run the revert command as well to complete the task. In many cases though, it's arguably better to leave your history alone and add a new revision reflecting the content of the last good state.

3.8.8   Reverting to the state of an earlier version

If you make an unwanted change but it doesn't make sense to uncommit it (because that code has been released to users say), you can use revert to take your working tree back to the desired state. For example:

% bzr commit "Fix bug #5"
Committed revision 20.
(release the code)
(hmm - bad fix)
bzr revert -r 19
bzr commit -m "Backout fix for bug #5"

This will change your entire tree back to the state as of revision 19, which is probably only what you want if you haven't made any new commits since then. If you have, the revert would wipe them out as well. In that case, you probably want to use Reverse cherrypicking instead to back out the bad fix.

Note: As an alternative to using an absolute bug number (like 19), you can specify one relative to the tip (-1) using a negative number like this:

bzr revert -r -2

3.8.9   Correcting a tag

If you have defined a tag prematurely, use the --force option of the tag command to redefine it. For example:

bzr tag 2.0-beta-1
(oops, we're not yet ready for that)
(make more commits to include more fixes)
bzr tag 2.0-beta-1 --force

3.8.10   Clearing a tag

If you have defined a tag and no longer want it defined, use the --delete option of the tag command to remove it. For example:

bzr tag 2.0-beta-4
(oops, we're not releasing a 4th beta)
bzr tag 2.0-beta-4 --delete

4   Sharing with peers

4.1   Working with another

4.1.1   Peer-to-peer rocks

In many cases, two minds can be better than one. You may be the one who started a project and someone wishes to help, or perhaps it's you who wants to help another. Perhaps you are both members of a larger team that have been assigned a task together as pair programmers. Either way, two people need to agree on a process, a set of guidelines and a toolset in order to work together effectively.

Imagine if you were not allowed to call someone on the phone directly and the only way to talk to them was by registering a conference call first? Companies and communities that only share code via a central VCS repository are living with a similar strait-jacket to that every day. There are times when central control makes a lot of sense and times when peer-to-peer rocks. Either way, Bazaar is designed to help.

4.1.2   The partner workflow

While it's certainly not the only way to do it, the partner workflow below is a good starting point for a pair of people who wish to collaborate using Bazaar.

images/workflows_peer.png

Over and above the tasks covered in the previous chapter, this chapter introduces two essential collaboration activities:

  • getting a copy of a branch
  • merging changes between branches.

Even when it's just you working on a code base, it can be very useful to keep multiple branches around (for different releases say) and to merge changes between them as appropriate. Your "partner" may indeed be yourself.

4.2   Branching a project

4.2.1   Branch URLs

Before someone else can get a copy of your work, you need to agree on a transfer technology. You may decide to make the top level directory of your branch a network share, an approach familiar to Windows users. Linux and OS X users might prefer access to be via SFTP, a secure protocol built-in to most SSH servers. Bazaar is very flexible in this regard with support for lots of protocols some of which are given below.

Prefix Description
file:// Access using the standard filesystem (default)
sftp:// Access using SFTP (most SSH servers provide SFTP).
bzr:// Fast access using the Bazaar smart server.
ftp:// Access using passive FTP.
http:// Read-only access to branches exported by a web server.

As indicated above, branches are identified using URLs with the prefix indicating the transfer technology. If no prefix is given, normal filenames are assumed. For a complete list of supported protocols, see the urlspec online help topic or the URL Identifiers section of the Bazaar User Reference.

4.2.2   A reminder about shared repositories

Before getting a copy of a branch, have a quick think about where to put it on your filesystem. For maximum storage efficiency down the track, it is recommended that branches be created somewhere under a directory that has been set up as a shared repository. For example:

bzr init-repo my-repo
cd my-repo

You are now ready to grab a branch from someone else and hack away.

4.2.3   The branch command

To get a copy of an existing branch, use the branch command. The syntax is:

bzr branch URL [directory]

If a directory is not given, one is created based on the last part of the URL. Here are some examples showing a network share URL and an sftp URL respectively:

bzr branch m:/cool-trunk
bzr branch sftp://bill@mary-laptop/cool-repo/cool-trunk

This example shows explicitly giving the directory name to use for the new branch:

bzr branch /home/mary/cool-repo/cool-trunk cool

4.2.4   Time and space considerations

Depending on the size of the branch being transferred and the speed and latency of the network between your computer and the source branch, this initial transfer might take some time. Subsequent updates should be much faster as only the changes are transferred then.

Keep in mind that Bazaar is transferring the complete history of the branch, not just the latest snapshot. As a consequence, you can be off the network (or disconnected from the network share) after branch completes but you'll still be able to log and diff the history of the branch as much as you want. Furthermore, these operations are quick as the history is stored locally.

Note that Bazaar uses smart compression technology to minimize the amount of disk space required to store version history. In many cases, the complete history of a project will take up less disk space than the working copy of the latest version.

As explained in later chapters, Bazaar also has support for lightweight checkouts of a branch, i.e. working trees with no local storage of history. Of course, disconnected usage is not available then but that's a tradeoff you can decide to make if local disk space is really tight for you. Support for limited lookback into history - history horizons - is currently under development as well.

4.2.5   Viewing branch information

If you wish to see information about a branch including where it came from, use the info command. For example:

bzr info cool

If no branch is given, information on the current branch is displayed.

4.3   Merging changes

4.3.1   Parallel development

Once someone has their own branch of a project, they can make and commit changes in parallel to any development proceeding on the original branch. Pretty soon though, these independent lines of development will need to be combined again. This process is known as merging.

4.3.2   The merge command

To incorporate changes from another branch, use the merge command. Its syntax is:

bzr merge [URL]

If no URL is given, a default is used, initially the branch this branch originated from. For example, if Bill made a branch from Mary's work, he can merge her subsequent changes by simply typing this:

bzr merge

On the other hand, Mary might want to merge into her branch the work Bill has done in his. In this case, she needs to explicitly give the URL the first time, e.g.:

bzr merge sftp://mary@bill-laptop/cool-repo/cool-trunk

This sets the default merge branch if one is not already set. To change the default after it is set, use the --remember option.

4.3.3   How does merging work?

A variety of algorithms exist for merging changes. Bazaar's default algorithm is a variation of 3-way merging which works as follows. Given an ancestor A and two branches B and C, the following table provides the rules used.

A B C Result Comment
x x x x unchanged
x x y y line from C
x y x y line from B
x y z ? conflict

Note that some merges can only be completed with the assistance of a human. Details on how to resolve these are given in Resolving conflicts.

4.3.4   Recording a merge

After any conflicts are resolved, the merge needs to be committed. For example:

bzr commit -m "Merged Mary's changes"

Even if there are no conflicts, an explicit commit is still required. Unlike some other tools, this is considered a feature in Bazaar. A clean merge is not necessarily a good merge so making the commit a separate explicit step allows you to run your test suite first to verify all is good. If problems are found, you should correct them before committing the merge or throw the merge away using revert.

4.3.5   Merge tracking

One of the most important features of Bazaar is distributed, high quality merge tracking. In other words, Bazaar remembers what has been merged already and uses that information to intelligently choose the best ancestor for a merge, minimizing the number and size of conflicts.

If you are a refugee from many other VCS tools, it can be really hard to "unlearn" the please-let-me-avoid-merging-at-any-cost habit. Bazaar lets you safely merge as often as you like with other people. By working in a peer-to-peer manner when it makes sense to do so, you also avoid using a central branch as an "integration swamp", keeping its quality higher. When the change you're collaborating on is truly ready for wider sharing, that's the time to merge and commit it to a central branch, not before.

Merging that Just Works truly can change how developers work together.

4.4   Resolving conflicts

4.4.1   Workflow

Unlike some other tools that force you to resolve each conflict during the merge process, Bazaar merges as much as it can and then reports the conflicts. This can make conflict resolution easier because the contents of the whole post-merge tree are available to help you decide how things ought to be resolved. You may also wish to selectively run tests as you go to confirm each resolution or group or resolutions is good.

4.4.2   Listing conflicts

As well as being reported by the merge command, the list of outstanding conflicts may be displayed at any time by using the conflicts command. It is also included as part of the output from the status command.

4.4.3   Resolving a conflict

When a conflict is encountered, the merge command puts embedded markers in each file showing the areas it couldn't resolve. It also creates 3 files for each file with a conflict:

  • foo.BASE
  • foo.THIS
  • foo.OTHER

where foo is the name of the conflicted file. In many cases, you can resolve conflicts by simply manually editing each file in question, fixing the relevant areas and removing the conflict markers as you go.

After fixing all the files in conflict, and removing the markers, ask Bazaar to mark them as resolved using the resolve command like this:

bzr resolve

Alternatively, after fixing each file, you can mark it as resolved like this:

bzr resolve foo

Among other things, the resolve command cleans up the BASE, THIS and OTHER files from your working tree.

4.4.4   Using the remerge command

In some cases, you may wish to try a different merge algorithm on a given file. To do this, use the remerge command nominating the file like this:

bzr remerge --weave foo

where foo is the file and weave is one of the available merge algorithms. This algorithm is particularly useful when a so-called criss-cross merge is detected, e.g. when two branches merge the same thing then merge each other. See the online help for criss-cross and remerge for further details.

4.4.5   Using external tools to resolve conflicts

If you have a GUI tool you like using to resolve conflicts, be sure to install the extmerge plugin. Once installed, it can be used like this:

bzr extmerge foo

where foo is the conflicted file. Rather than provide a list of files to resolve, you can give the --all option to implicitly specify all conflicted files.

The extmerge command uses the tool specified by the external_merge setting in your bazaar.conf file. If not set, it will look for some popular merge tools such as kdiff3 or opendiff, the latter being a command line interface to the FileMerge utility in OS X.

4.5   Annotating changes

4.5.1   Seeing the origin of content

When two or more people are working on files, it can be highly useful at times to see who created or last changed certain content. To do this, using the annotate command like this:

bzr annotate readme.txt

If you are a pessimist or an optimist, you might prefer to use one of built-in aliases for annotate: blame or praise. Either way, this displays each line of the file together with information such as:

  • who changed it last
  • when it was last changed
  • the commit message.

4.5.2   GUI tools

The various GUI plugins for Bazaar provide graphical tools for viewing annotation information. For example, the bzr-gtk plugin provides a GUI tool for this that can be launched using the gannotate command:

bzr gannotate readme.txt

The GUI tools typically provide a much richer display of interesting information (e.g. all the changes in each commit) so you may prefer them over the text-based command.

5   Team collaboration, central style

5.1   Centralized development

5.1.1   Motivation

Rather than working in parallel and occasionally merging, it can be useful at times to work in lockstep, i.e. for multiple people to be continuously committing changes to a central location, merging their work with the latest content before every commit.

This workflow is very familiar to users of central VCS tools like Subversion and CVS. It is also applicable to a single developer who works on multiple machines, e.g. someone who normally works on a desktop computer but travels with a laptop, or someone who uses their (Internet connected) home computer to complete office work out of hours.

If centralized development works well for your team already, that's great. Many teams begin using Bazaar this way and experiment with alternative workflows later.

5.1.2   Centralized workflow

The diagram below provides an overview of the centralized workflow.

images/workflows_centralized.png

Even if your team is planning to use a more distributed workflow, many of the tasks covered in this chapter may be useful to you, particularly how to publish branches.

5.2   Publishing a branch

5.2.1   Setting up a central repository

While the centralized workflow can be used by socially nominating any branch on any computer as the central one, in practice most teams have a dedicated server for hosting central branches.

Just as it's best practice to use a shared repository locally, it's advisable to put central branches in a shared repository. Note that central shared branches typically only want to store history, not working copies of files, so their enclosing repository is usually creating using the no-trees option, e.g.:

bzr init-repo --no-trees sftp://centralhost/srv/bzr/X-repo/

You can think of this step as similar to setting up a new cvsroot or Subversion repository. However, Bazaar gives you more flexibility in how branches may be organised in your repository. See Choosing a shared repository layout in the appendices for guidelines and examples.

5.2.2   Starting a central branch

There are two ways of populating a central branch with some initial content:

  1. Making a local branch and pushing it to a central location
  2. Making an empty central branch then committing content to it.

Here is an example of the first way:

bzr init-repo X-repo
bzr init X-repo/X-trunk
cd X-repo/X-trunk
cp -ar ~/X .     (copy files in using OS-specific tools)
bzr add
bzr commit -m "Initial import"
(local branch has content - publish it centrally now)
bzr push sftp://centralhost/srv/bzr/X-repo/X-trunk

Here is an example of the second way:

bzr init-repo X-repo
cd X-repo
bzr init sftp://centralhost/srv/bzr/X-repo/X-trunk
bzr checkout sftp://centralhost/srv/bzr/X-repo/X-trunk
cd X-trunk
cp -ar ~/X .     (copy files in using OS-specific tools)
bzr add
bzr commit -m "Initial import"

Note that committing inside a working tree created using the checkout command implicitly commits the content to the central location as well as locally. Had we used the branch command instead of checkout above, the content would have only been committed locally.

Working trees that are tightly bound to a central location like this are called checkouts. The rest of this chapter explains their numerous features in more detail.

5.3   Using checkouts

5.3.1   Turning a branch into a checkout

If you have a local branch and wish to make it a checkout, use the bind command like this:

bzr bind sftp://centralhost/srv/bzr/X-repo/X-trunk

This is necessary, for example, after creating a central branch using push as illustrated in the previous section.

After this, commits will be applied to the bound branch before being applied locally.

5.3.2   Turning a checkout into a branch

If you have a checkout and wish to make it a normal branch, use the unbind command like this:

bzr unbind

After this, commits will only be applied locally.

5.3.3   Getting a checkout

When working in a team using a central branch, one person needs to provide some initial content as shown in the previous section. After that, each person should use the checkout command to create their local checkout, i.e. the sandbox in which they will make their changes.

Unlike Subversion and CVS, in Bazaar the checkout command creates a local full copy of history in addition to creating a working tree holding the latest content. This means that operations such as diff and log are fast and can still be used when disconnected from the central location.

5.3.4   Getting a lightweight checkout

While Bazaar does its best to efficiently store version history, there are occasions when the history is simply not wanted. For example, if your team is managing the content of a web site using Bazaar with a central repository, then your release process might be as simple as updating a checkout of the content on the public web server. In this case, you probably don't want the history downloaded to that location as doing so:

  • wastes disk space holding history that isn't needed there
  • exposes a Bazaar branch that you may want kept private.

To get a history-less checkout in Bazaar, use the --lightweight option like this:

bzr checkout --lightweight sftp://centralhost/srv/bzr/X-repo/X-trunk

Of course, many of the benefits of a normal checkout are lost by doing this but that's a tradeoff you can make if and when it makes sense.

Note: If your code base is really large and disk space on your computer is limited, lightweight checkouts may be the right choice for you. Be sure to consider all your options though including shared repositories and Reusing a checkout as explained later.

5.3.5   Updating to the latest content

One of the important aspects of working in lockstep with others is keeping your checkout up to date with the latest changes made to the central branch. Just as you would in Subversion or CVS, you do this in Bazaar by using the update command like this:

bzr update

This gets any new revisions available in the bound branch and merges your local changes, if any.

5.3.6   Handling commit failures

Note that your checkout must be up to date with the bound branch before running commit. Bazaar is actually stricter about this than Subversion or CVS - you need to be up to date with the full tree, not just for the files you've changed. Bazaar will ask you to run update if it detects that a revision has been added to the central location since you last updated.

If the network connection to the bound branch is lost, the commit will fail. Some alternative ways of working around that are outlined next.

5.4   Working offline on a central branch

5.4.1   The centralized with local commits workflow

If you lose your network connection because you are travelling, the central server goes down, or you simply want to snapshot changes locally without publishing them centrally just yet, this workflow is for you.

images/workflows_localcommit.png

5.4.2   Committing locally

If you're working in a checkout and need/wish to commit locally only, add the --local option to the commit command like this:

bzr commit --local

5.4.3   Being disconnected for long time periods

If you will be or want to be disconnected from the bound branch for a while, then remembering to add --local to every commit command can be annoying. An alternative is to use the unbind command to make the checkout temporarily into a normal branch followed by the bind command at some later point in time when you want to keep in lockstep again.

Note that the bind command remembers where you were bound to last time this branch was a checkout so it isn't necessary to enter the URL of the remote branch when you use bind after an earlier unbind.

5.4.4   Merging a series of local commits

When you make commits locally independent of ongoing development on a central branch, then Bazaar treats these as two lines of development next time you update. In this case, update does the following:

  • it brings the latest revisions from the bound branch down and makes that the mainline of development within your checkout
  • it moves your local changes since you last updated into a logical parallel branch
  • it merges these together so that your local changes are reported as a pending merge by status.

As always, you will need to run commit after this to send your work to the central branch.

5.5   Reusing a checkout

5.5.1   Motivation

At times, it can be useful to have a single checkout as your sandbox for working on multiple branches. Some possible reasons for this include:

  • saving disk space when the working tree is large
  • developing in a fixed location.

In many cases, working tree disk usage swamps the size of the .bzr directory. If you want to work on multiple branches but can't afford the overhead of a full working tree for each, reusing a checkout across multiples branches is the way to go.

On other occasions, the location of your sandbox might be configured into numerous development and testing tools. Once again, reusing a checkout across multiple branches can help.

5.5.2   Changing where a branch is bound to

To change where a checkout is bound to, follow these steps:

  1. Make sure that any local changes have been committed centrally so that no work is lost.
  2. Use the bind command giving the URL of the new remote branch you wish to work on.
  3. Make your checkout a copy of the desired branch by using the update command followed by the revert command.

Note that simply binding to a new branch and running update merges in your local changes, both committed and uncommitted. You need to decide whether to keep them or not by running either revert or commit.

An alternative to the bind+update recipe is using the switch command. This is basically the same as removing the existing branch and running checkout again on the new location, except that any uncommitted changes in your tree are merged in.

Note: As switch can potentially throw away committed changes in order to make a checkout an accurate cache of a different bound branch, it will fail by design if there are changes which have been committed locally but are not yet committed to the most recently bound branch. To truly abandon these changes, use the --force option.

5.5.3   Switching a lightweight checkout

With a lightweight checkout, there are no local commits and switch effectively changes which branch the working tree is associated with. One possible setup is to use a lightweight checkout in combination with a local tree-less repository. This lets you switch what you are working on with ease. For example:

bzr init-repo --no-trees X-repo
cd X-repo
bzr branch sftp://centralhost/srv/bzr/X-repo/X-trunk
bzr checkout --lightweight X-trunk my-sandbox
cd my-sandbox
(hack away)

Note that X-trunk in this example will have a .bzr directory within it but there will be no working tree there as the branch was created in a tree-less repository. You can grab or create as many branches as you need there and switch between them as required. For example:

(assuming in my-sandbox)
bzr branch sftp://centralhost/srv/bzr/X-repo/X-1.0 ../X-1.0
bzr switch ../X-1.0
(fix bug in 1.0)
bzr commit -m "blah, blah blah"
bzr switch ../X-trunk
(go back to working on the trunk)

Note: The branches may be local only or they may be bound to remote ones (by creating them with checkout or by using bind after creating them with branch).

6   Team collaboration, distributed style

6.1   Distributed development

6.1.1   Motivation

Distributed VCS tools offer new ways of working together, ways that better reflect the modern world we live in and ways that enable higher quality outcomes.

6.1.2   The decentralized with shared mainline workflow

In this workflow, each developer has their own branch or branches, plus commit rights to the main branch. They do their work in their personal branch, then merge it into the mainline when it is ready.

images/workflows_shared.png

Other distributed workflows are explored later in this chapter.

6.2   Organizing branches

6.2.1   Mirror branches

A primary difference when using distributed workflows to develop is that your main local branch is not the place to make changes. Instead, it is kept as a pristine copy of the central branch, i.e. it's a mirror branch.

To create a mirror branch, set-up a shared repository (if you haven't already) and then use the branch (or checkout) command to create the mirror. For example:

bzr init-repo X-repo
cd X-repo
bzr branch sftp://centralhost/srv/bzr/X-repo/X-trunk

6.2.2   Task branches

Each new feature or fix is developed in its own branch. These branches or referred to as feature branches * or *task branches - the terms are used interchangably.

To create a task branch, use the branch command against your mirror branch. For example:

bzr branch X-trunk X-fix-123
cd X-fix-123
(hack, hack, hack)

There are numerous advantages to this approach:

  1. You can work on multiple changes in parallel
  2. There is reduced coupling between changes
  3. Multiple people can work in a peer-to-peer mode on a branch until it is ready to go.

In particular, some changes take longer to cook than others so you can ask for reviews, apply feedback, ask for another review, etc. By completing work to sufficient quality in separate branches before merging into a central branch, the quality and stability of the central branch are maintained at higher level than they otherwise would be.

6.2.3   Refreshing a mirror branch

Use the pull command to do this:

cd X-trunk
bzr pull

6.2.4   Merging the latest trunk into a feature branch

Use the merge command to do this:

cd X-fix-123
bzr merge
(resolve any conflicts)
bzr commit -m "merged X-trunk"

6.2.5   Merging a feature into the trunk

The policies for different distributed workflows vary here. The simple case where all developers have commit rights to the main trunk are shown below.

If your mirror is a checkout:

cd X-trunk
bzr update
bzr merge ../X-fix-123
(resolve any conflicts)
bzr commit -m "Fixed bug #123"

If your mirror is a branch:

cd X-trunk
bzr pull
bzr merge ../X-fix-123
(resolve any conflicts)
bzr commit -m "Fixed bug #123"
bzr push

6.2.6   Backing up task branches

One of the side effects of centralized workflows is that changes get frequently committed to a central location which is backed up as part of normal IT operations. When developing on task branches, it is a good idea to publish your work to a central location (but not necessarily a shared location) that will be backed up. You may even wish to bind local task branches to remote ones established on a backup server just for this purpose.

6.3   Using gatekeepers

6.3.1   The decentralized with human gatekeeper workflow

In this workflow, one developer (the gatekeeper) has commit rights to the main branch while other developers have read-only access. All developers make their changes in task branches.

images/workflows_gatekeeper.png

When a developer wants their work merged, they ask the gatekeeper to review their change and merge it if acceptable. If a change fails review, further development proceeds in the relevant task branch until it is good to go.

Note that a key aspect of this approach is the inversion of control that is implied: developers no longer decide when to "commit/push" changes into the central branch: the code base evolves by gatekeepers "merging/pulling" changes in a controlled manner. It's perfectly acceptable, indeed common, to have multiple central branches with different gatekeepers, e.g. one branch for the current production release and another for the next release. In this case, a task branch holding a bug fix will most likely be advertized to both gatekeepers.

One of the great things about this workflow is that it is hugely scalable. Large projects can be broken into teams and each team can have a local master branch managed by a gatekeeper. Someone can be appointed as the primary gatekeeper to merge changes from the team master branches into the primary master branch when team leaders request it.

6.3.2   The decentralized with automatic gatekeeper workflow

To obtain even higher quality, all developers can be required to submit changes to an automated gatekeeper that only merges and commits a change if it passes a regression test suite. One such gatekeeper is a software tool called PQM.

images/workflows_pqm.png

For further information on PQM, see https://launchpad.net/pqm.

6.4   Sending changes

6.4.1   Motivation

In many distributed development scenarios, it isn't always feasible for developers to share task branches by advertising their URLs. For example, a developer working on a laptop might take it home overnight so his/her task branches could well be inaccessible whe