8
This document describes some basic workflow for using Bazaar_. This doesn't
9
try to explain *why* every step is done, but more gives recommendations
10
about what is considered a good way to work with Bazaar_.
11
Bazaar_ is designed to be very flexible in workflows, from fully
12
decentralized to mostly centralized.
13
The practices here are meant to help ease the user into more advanced usage
14
of Bazaar_, and allowing them to work in a mix of centralized and
15
decentralized operation.
17
In general, this document is meant for people in a work setting. Where
18
several people are working on the same codebase, and want to work with
19
eachother and keep in sync. However, this workflow is also applicable to a
20
single developer, who might work on several machines, and wants to keep in
23
.. _Bazaar: http://bazaar-vcs.org
29
These are some reasonably simple steps to setup Bazaar_ so that it works
36
Your user identity is stored with each commit. While this doesn't have to
37
be accurate, unique, or anything else, it will be used in log messages an
38
annotations, so it is nice to have something real.::
40
% bzr whoami "John Doe <jdoe@organization.com>"
43
Setting up a local Repository
44
-----------------------------
46
Bazaar_ branches generally copy the history information around with them,
47
which is part of how you can work in a fully decentralized manner. As an
48
optimization, it is possible for branches to combine their storage needs,
49
so that you do not need to copy around all of this history information
50
whenever you create a new branch.
52
The best way to do this is to create a `Shared Repository`_. In general,
53
branches will share their storage if they exist in a subdirectory of a
54
`Shared Repository`_. So lets setup a `Shared Repository`_ in our home
55
directory, thus all branches we create underneath will share their history
58
% bzr init-repo --trees ~
61
Setting up a remote Repository
62
------------------------------
64
Many times you want a location where data is stored separate from where
65
you do your work. This workflow is required by centralized systems (CVS/SVN).
66
Usually they are on separate machines, but not always. This is actually a
67
pretty good setup, especially in a work environment. Because it ensures
68
a central location where data can be backed up, and means that if something
69
happens to a developer's machine, no committed work has been lost.
71
So lets set up a shared location for our project. Again, we will use a
72
`Shared Repository`_ to optimize disk usage.::
74
% bzr init-repo --no-trees sftp://centralhost/srv/bzr/
76
You can think of this step as similar to setting up a new cvsroot, or
77
subversion repository (only obviously it is a little bit simpler).
80
Starting to version an existing project
81
=======================================
83
Now that we have a repository, lets get going with a new project. Most of
84
the time, you will already have some code that you started working with,
85
that you now want to version using Bazaar_. If the code was originally
86
in source control, there are many ways to convert the project to Bazaar_
87
without losing any history. However, this is outside of the scope of this
88
document. See XXXReferenceConversionOfHistory_.
91
Developer 1: Creating the first revision
92
----------------------------------------
94
So first, we want to create a branch in our remote Repository, where we
95
will want to host the project. Let's assume we have a project named
96
"sigil" that we want to start versioning, and create an empty branch::
98
% bzr init sftp://centralhost/srv/bzr/sigil
100
This can be thought of as the "HEAD" branch in CVS terms, or as the "trunk"
101
in Subversion terms. We typically call this the ``dev`` branch.
103
I prefer working in a subdirectory of ``$HOME`` to avoid collisions with all
104
the other stuff that ends up in ``$HOME``. Also, we will want a project
105
directory where we can hold all of the different branches we end up
113
% bzr checkout sftp://centralhost/srv/bzr/sigil dev
117
% bzr commit -m "Initial import of Sigil"
119
There are many ways to setup your working directory, but the above way
120
will makes it easy to handle working with feature/bugfix branches. And one
121
of the strong points of Bazaar_ is how well it works with branches.
123
At this point, because you have a 'checkout' of the remote branch, any
124
commits you make in ``dev/`` will automatically be saved both locally,
125
and on ``centralhost``.
128
Developer N: Getting a working copy of the project
129
--------------------------------------------------
131
Since the first developer did all of the work of creating the project,
132
all other developers can just get a checkout of that branch. They should
133
still follow `Setting User Email`_ and `Setting up a local Repository`_.
135
Then to get a copy of the current tip::
138
% bzr checkout sftp://centralhost/srv/bzr/sigil dev
140
Now that two people both have a checkout of
141
``sftp://centralhost/srv/bzr/sigil``, there will be times when one of
142
them is out of date with the current version. Bazaar_ will inform the user
143
of this and prevent them from committing. To get up to date use ``bzr
144
update``, which will update the tree with the remote changes. This may
145
require resolving conflicts, in the case that the same files have been
149
Developing on separate branches
150
===============================
152
So far everyone is working and committing their changes into the same
153
branch. Which means that everyone needs to update fairly regularly, and
154
deal with other people's changes. Also, if one person commits something
155
which breaks the codebase, then everyone has to deal with it.
157
Usually, it is better to do development on individual branches, and then
158
integrate those back into the main branch, once they are stable. This is
159
one of the biggest changes from working with CVS/SVN. They both allow you
160
to work on separate branches, but their merging algorithms are fairly
161
weak, so it is difficult to keep things synchronized. Bazaar_ merges track
162
what has already been merged, and can even apply changes to files that
166
Creating and working on a new branch
167
------------------------------------
169
We want to keep our changes available for other people, even if they
170
aren't quite complete yet. So we will create a new public branch, and
174
% bzr branch sftp://centralhost/srv/bzr/sigil \
175
sftp://centralhost/srv/bzr/sigil/doodle-fixes
176
% bzr checkout sftp://centralhost/srv/bzr/sigil/doodle-fixes doodle-fixes
179
We now have a place to make any fixes to doodles that we need. And we
180
won't interrupt people who are working on other parts of the code.
181
Because we have a checkout, any commits made in the ``doodle-fixes/`` will
182
also show up on ``centralhost``.
183
It is also completely possible to have 2 developers collaborate on one of
184
these branches, just like they would have collaborated on the ``dev``
187
.. [#cbranch] When using lots of independent branches, having to retype
188
the full URL all the time takes a lot of typing. We are looking into
189
various methods to help with this, such as branch aliases, etc. For
190
now, though, the bzrtools_ plugin provides the ``bzr cbranch`` command.
191
Which is designed to take a base branch, create a new public branch,
192
and create a checkout of that branch, all with much less typing.
193
Configuring ``cbranch`` is outside the scope of this document, but the
194
final commands look like ``bzr cbranch dev my-feature-branch``
196
.. _bzrtools: https://launchpad.net/products/bzrtools
202
When it is decided that some of the changes in ``doodle-fixes`` is ready
203
to be merged into the main tree, simply do::
205
% cd ~/work/sigil/dev
206
% bzr merge ../doodle-fixes
208
Now the changes are available in the ``dev`` branch, but they haven't been
209
committed yet. This is the time when you want to review the final changes,
210
and make sure they are what you want. ``bzr status`` and ``bzr diff`` are
211
good tools to use here. Also, there may be some conflicts in files, if
212
there were changes made to the same file. Bazaar_ will prevent you from
213
committing until you have resolved these conflicts. That way you don't
214
accidentally commit the conflict markers. ``bzr status`` will show the
215
conflicts along with the other changes, or you can use ``bzr conflicts``
216
to just list conflicts. Use ``bzr resolve file/name`` or ``bzr resolve
217
--all`` once conflicts have been handled.[#resolve]_
218
If you have a conflict that is particularly difficult to solve you may
219
want to use the ``bzr remerge`` command. It will let you try different
220
merge algorithms, as well as let you see the original source lines
223
.. [#resolve] Some systems make you resolve conflicts as part of the merge
224
process. We have found that it is usually easier to resolve conflicts
225
when you have the view of the entire tree, rather than just a single
226
file. It gives you much more context, and also lets you run tests as
227
you resolve the problems.
230
Recommended Branching
231
---------------------
233
One very common way to handle all of these branches is to give each
234
developer their own branch, and their own place to work in the central
235
location. This can be done with::
237
% bzr branch sftp://centralhost/srv/bzr/sigil \
238
sftp://centralhost/srv/bzr/sigil/user-a
239
% bzr branch sftp://centralhost/srv/bzr/sigil \
240
sftp://centralhost/srv/bzr/sigil/user-b
242
This gives each developer their own branch to work on. And, they can
243
easily create a new feature branch for themselves with just[#cbranch]_::
245
% bzr branch sftp://centralhost/srv/bzr/sigil/user-a \
246
sftp://centralhost/srv/bzr/sigil/user-a/feature
248
% bzr checkout sftp://centralhost/srv/bzr/sigil/user-a/feature myfeature
257
Bazaar_ has the concept of a `Shared Repository`_. This is similar to the
258
concept of other RCS's repository. Such as in Subversion, where you have a
259
remote repository, which is where all of the history is stored, and
260
locally you don't have any history information, only a checkout of the
261
working tree files. Note that "Shared" in this context means shared
262
between branches. It *may* be shared between people, but standalone
263
branches can also be shared between people.
265
In Bazaar_ terms, a `Shared Repository`_ is a location where multiple
266
branches can **share** their revision history information. Because Bazaar_
267
wants to support decentralized workflows, it is possible for every branch
268
to maintain its own revision history information. But this is often
269
inefficient, since often branches share history, and they might as well
270
share the storage as well.
274
vim: tw=74 ft=rst spell spelllang=en_us