Bazaar in five minutes for web devs
In some workflows you will have access to different computers all the time and need to do version controlled changes at each of your workstations. In fact you may also need to do some of your work directly on the server! Bazaar can help you to keep all of these versions correctly up-to-date. In this example we specifically look at how to use Bazaar to coordinate between a server and a home network environment that does not have a fixed network address and therefore cannot easily receive a "pushed", but wants to push and commit updates to a remote server. Additional information about various set-ups for Bazaar are available on the Workflows page.
This tutorial assumes you have a networked machine (the server) and a machine that is occasionally connected to the Internet (the laptop), but is not readily accessible from the outside world. It also assumes you are comfortable working at the command line. If you have some machines that will never be accessed directly you should consider using the bzr-upload plugin to push your files to this machine.
In this tutorial we will set up two machines. You may set up more if your situation warrants it.
Bazaar installation instructions are available from: http://bazaar-vcs.org/Download
To start you need to install bzr on all machines that will be editing files directly. There is a very simple set of instructions which can be used to install bzr onto a shared hosting server: http://doc.bazaar-vcs.org/bzr.dev/en/mini-tutorial/index.html (and also update your path in .bashrc)
Let's assume you are starting this project from scratch. Your files are available on your laptop, but not the server. The first thing you need to do is to convert your project's files into a working tree by initializing a Bazaar branch within your project's directory.
Change directories into your project directory (note, these steps are done within the project directory, not from above).
- initalize the directory:
- bzr init
- check to see that a hidden .bzr folder has been created:
- ls -al
- add all files in your project to the revision control system:
- bzr add
Note: This will include all files in the directory, and sub-directories. If you want to include only a few files, you may add them individually, or as a batch, with:
- bzr add [FILE...]
If you would like to omit sub-directories you may choose to add only files in the current directory with the --no-recurse parameter as follows:
- bzr add --no-recurse
You may also choose to "ignore" some types of files, or directories. Additional information is available from the command line help with:
- bzr --help ignore
Once your files have all been added to Bazaar, you will need to take a snapshot of them. This will start a change history in the .bzr hidden directory (this means you do NOT need to be connected to the Internet to commit your files to a revision control system).
- bzr commit -m "Initial import of all project files"
- proceed with your work, checking your files into the repository as appropriate with the commit command. Update the message so that it matches your work.
- bzr commit -m "draft of feature XYZ finished, ready to test on dev server."
When you are ready to upload the files to the server you will need to install the bzr-push-and-update plugin. This plugin is installed only on the laptop machine and is only necessary if you want to force a remote machine to update its files on push from your local machine. Any changes that are made on the server will be pulled back down to the laptop and merged into that branch. Use the following steps to install the bzr-push-and-update plugin.
- change directories to your local Bazaar plugin directory (~/.bazaar/plugins). This directory may not exist, if it does not exist you will need to create it now.
- mkdir ~/.bazaar/plugins
- cd ~/.bazaar/plugins
- install the bzr-push-and-update plugin, and initialize the python scripts:
bzr branch https://launchpad.net/bzr-push-and-update push_and_update
Create a new .bzr branch on the server. Note this uploads the change history and general bzr working files only. It does not upload the files to the server (yet!). This command assumes the directory does not yet exist on the remote server. Please update the username, servername.com and /path/to/files as appropriate for your system.
bzr push --create-prefix sftp://firstname.lastname@example.org/~/path/on/server/to/put/files
This may take a while. When it has completed you will see a message printed to the screen that reads, "Created new branch."
Note: At this point you will not have a "checkout" directory on the server. You will not be able to run the second part of this process without it. At this point you must log into the server and run the checkout command.
- cd /path/on/server/to/put/files
- bzr checkout
You are now ready to work from either branch on either computer.
To push updates from your laptop and immediately publish the altered files (by performing a remote update) use the "push" option as you normally would. The push-and-update plugin alters the behaviour of the default "push" to include the remote update step. To use the plugin, push files as you normally would with the command:
bzr push sftp://email@example.com/~/path/on/server/to/put/files
For subsequent pushes you can omit the remote path. Bazaar will remember where to put the files.
If you have been working on the server you will need to merge changes down to your laptop.
bzr merge sftp://firstname.lastname@example.org/~/path/on/server/
Note: The URL should be remembered and can be omitted if you prefer. This shortens the command to: bzr merge.
For additional information on using Bazaar, please refer to the full documentation on this site. http://bazaar-vcs.org/Documentation