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
8
This document describes a possible workflow for using Bazaar_. That of
9
using Bazaar_, the distributed version control system, in a centralized
10
manner. Bazaar_ is designed to be very flexible and allows several
11
different workflows, from fully decentralized to mostly centralized. The
12
workflow used here is meant to ease a new user into more advanced usage of
13
Bazaar_, and allows them to work in a mix of centralized and decentralized
16
In general, this document is meant for users coming from a background of
17
centralized version control systems such as CVS or subversion. It is
18
common in work settings to have a single central server hosting the
19
codebase, with several people working on this codebase, keeping their work
20
in sync. This workflow is also applicable to a single developer working
21
on several different machines.
23
23
.. _Bazaar: http://bazaar-vcs.org
29
29
These are some reasonably simple steps to setup Bazaar_ so that it works
36
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
-----------------------------
37
be accurate or unique, it will be used in log messages and
38
annotations, so it is better to have something real.
42
% bzr whoami "John Doe <jdoe@organization.com>"
45
2- Setting up a local Repository
46
--------------------------------
46
48
Bazaar_ branches generally copy the history information around with them,
47
49
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.
50
optimization, it is possible for related branches to combine their storage
51
needs so that you do not need to copy around all of this history
52
information whenever you create a new branch.
52
54
The best way to do this is to create a `Shared Repository`_. In general,
53
55
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
56
`Shared Repository`_. So let's setup a `Shared Repository`_ in our home
55
57
directory, thus all branches we create underneath will share their history
58
62
% 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.::
65
3- Setting up a remote Repository
66
---------------------------------
68
Many times you want a location where data is stored separately from where
69
you do your work. This workflow is required by centralized systems
70
(CVS/SVN). Usually they are on separate machines, but not always. This is
71
actually a pretty good setup, especially in a work environment. Since it
72
ensures a central location where data can be backed up, and means that if
73
something happens to a developer's machine, no committed work has to be
76
So let's set up a shared location for our project on a remote machine
77
called ``centralhost``. Again, we will use a
78
`Shared Repository`_ to optimize disk usage.
74
82
% bzr init-repo --no-trees sftp://centralhost/srv/bzr/
76
84
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
subversion repository.
88
III- Versioning an existing project
89
===================================
91
Now that we have a repository, let's create a versioned project. Most of
92
the time, you will already have some code that you are working with,
85
93
that you now want to version using Bazaar_. If the code was originally
86
94
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
----------------------------------------
95
without losing any history. However, this is outside the scope of this
96
document. See `Tracking Upstream`_ for some possibilities (section
97
"Converting and keeping history").
99
.. _Tracking Upstream: http://bazaar-vcs.org/TrackingUpstream
102
XXX: We really need a different document for discussing conversion of a
103
project. Right now TrackingUpstream is the best we have, though.
106
1- Developer 1: Creating the first revision
107
-------------------------------------------
94
109
So first, we want to create a branch in our remote Repository, where we
95
110
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::
111
"sigil" that we want to start versioning.
98
115
% bzr init sftp://centralhost/srv/bzr/sigil
100
117
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.
118
in Subversion terms. We will 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
120
I prefer working in a subdirectory of my home directory to avoid collisions with all
121
the other files that end up there. Also, we will want a project
105
122
directory where we can hold all of the different branches we end up
117
136
% 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
139
In the example above, we created an empty branch (the ``/sigil`` branch)
140
on ``centralhost``, and then checkout out this empty branch onto our
141
workstation to add files from our existing project.
142
There are many ways to setup your working directory, but the steps above
143
make it easy to handle working with feature/bugfix branches. And one
121
144
of the strong points of Bazaar_ is how well it works with branches.
123
146
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,
147
commits you make in ``~/work/sigil/dev/`` will automatically be saved both locally,
125
148
and on ``centralhost``.
128
Developer N: Getting a working copy of the project
129
--------------------------------------------------
151
2- Developer N: Getting a working copy of the project
152
-----------------------------------------------------
131
154
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`_.
155
all other developers would just checkout that branch. **They should
156
still follow** `1- Setting User Email`_ and `2- Setting up a local Repository`_.
135
Then to get a copy of the current tip::
158
To get a copy of the current development tree::
137
160
% cd ~/work/sigil
138
161
% bzr checkout sftp://centralhost/srv/bzr/sigil dev
140
163
Now that two people both have a checkout of
141
164
``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
===============================
165
the checkouts will be out of date with the current version.
166
At commit time, Bazaar_ will inform the user of this and prevent them from
167
committing. To get up to date, use ``bzr update`` to update the
168
tree with the remote changes. This may require resolving conflicts, if the
169
same files have been modified.
172
IV- Developing on separate branches
173
===================================
152
175
So far everyone is working and committing their changes into the same
153
branch. Which means that everyone needs to update fairly regularly, and
176
branch. This means that everyone needs to update fairly regularly and
154
177
deal with other people's changes. Also, if one person commits something
155
which breaks the codebase, then everyone has to deal with it.
178
that breaks the codebase, then upon syncing, everyone will get the
157
Usually, it is better to do development on individual branches, and then
181
Usually, it is better to do development on different branches, and then
158
182
integrate those back into the main branch, once they are stable. This is
159
183
one of the biggest changes from working with CVS/SVN. They both allow you
160
184
to work on separate branches, but their merging algorithms are fairly
161
weak, so it is difficult to keep things synchronized. Bazaar_ merges track
185
weak, so it is difficult to keep things synchronized. Bazaar_ tracks
162
186
what has already been merged, and can even apply changes to files that
163
187
have been renamed.
166
Creating and working on a new branch
167
------------------------------------
190
1- Creating and working on a new branch
191
---------------------------------------
169
193
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
194
aren't quite complete yet. So we will create a new public branch on
195
``centralhost``, and track it locally.
173
199
% cd ~/work/sigil
174
200
% bzr branch sftp://centralhost/srv/bzr/sigil \
193
223
Configuring ``cbranch`` is outside the scope of this document, but the
194
224
final commands look like ``bzr cbranch dev my-feature-branch``
196
.. [#nestedbranches] It may look odd to have a branch in a subdirectory of
197
another branch. However, this is just fine, and you can think of it as
198
a heirarchial namespace. Where the nested branch is derived from the
201
226
.. _bzrtools: https://launchpad.net/products/bzrtools
229
2- Merging changes back
230
-----------------------
207
When it is decided that some of the changes in ``doodle-fixes`` is ready
208
to be merged into the main tree, simply do::
232
When it is decided that some of the changes in ``doodle-fixes`` are ready
233
to be merged into the main branch, simply do::
210
235
% cd ~/work/sigil/dev
211
236
% bzr merge ../doodle-fixes
213
Now the changes are available in the ``dev`` branch, but they haven't been
214
committed yet. This is the time when you want to review the final changes,
215
and make sure they are what you want. ``bzr status`` and ``bzr diff`` are
216
good tools to use here. Also, there may be some conflicts in files, if
217
there were changes made to the same file. Bazaar_ will prevent you from
218
committing until you have resolved these conflicts. That way you don't
219
accidentally commit the conflict markers. ``bzr status`` will show the
220
conflicts along with the other changes, or you can use ``bzr conflicts``
221
to just list conflicts. Use ``bzr resolve file/name`` or ``bzr resolve
222
--all`` once conflicts have been handled.[#resolve]_
223
If you have a conflict that is particularly difficult to solve you may
224
want to use the ``bzr remerge`` command. It will let you try different
225
merge algorithms, as well as let you see the original source lines
238
Now the changes are available in the ``dev`` branch, but they have not
239
been committed yet. This is the time when you want to review the final
240
changes, and double check the code to make sure it compiles cleanly and
241
passes the test suite. The commands ``bzr status`` and ``bzr diff`` are
242
good tools to use here. Also, this is the time to resolve any conflicts.
243
Bazaar_ will prevent you from committing until you have resolved these
244
conflicts. That way you don't accidentally commit the conflict markers.
245
The command ``bzr status`` will show the conflicts along with the other
246
changes, or you can use ``bzr conflicts`` to just list conflicts. Use
247
``bzr resolve file/name`` or ``bzr resolve --all`` once conflicts have
248
been handled. [#resolve]_ If you have a conflict that is particularly
249
difficult to solve you may want to use the ``bzr remerge`` command. It
250
will let you try different merge algorithms, as well as let you see the
251
original source lines (``--show-base``).
228
253
.. [#resolve] Some systems make you resolve conflicts as part of the merge
229
254
process. We have found that it is usually easier to resolve conflicts