Working together - git and bazaar

Git and Bazaar - playing nicely together? In this example shows how we can checkout a Bazaar repository into git, and (through a round-about way) get our changes back into it.

Install the required packages

Warning: You probably need a debian-based distribution for this. Some of these tools simply aren't avaiable yet on platforms such as Windows, Mac OS-X. These commands were all tested on ubuntu 9.10 (karmic).

aptitude install -y git-core git-completion bzr bzr-git bzr-fastimport

Clone a bzr repository into git

mkdir <git_repo_name> && cd <git_repo_name> && git init
bzr fast-export --export-marks=.git/bzr.mark <bzr_remote> | git fast-import --export-marks=.git/git.mark
git checkout master

Mirror our bzr repository as a git repository

Now our bzr repo is in git, we can push it out public git repositories, too. Just as you would for any regular git repository.

# For gitosis, first create a new repository
git remote add origin <hosted_git_url>

# For github
gem install github
github create-from-local

<make changes>
git push origin master

Get updates from the original bzr repository

Whenever the bazaar repository is updated online, we'd like to download those into our git repositry.

cd <git_repo_name>
bzr fast-export --import-marks=.git/bzr.mark --export-marks=.git/bzr.mark <bzr_repo>/trunk | \
git fast-import --import-marks=.git/git.mark --export-marks=.git/git.mark

Import into 'updated' .bzr repo

To get changes back into Bazaar requires a local Bazaar repository. We cannot push changes directly to the Bazaar remote from git. Effectively it shall serve as our outbox, so we'll called it <repo_name>.bzr-out.

cd ..
bzr git-import <repo_name> <repo_name>.bzr-out

Note that we don't need create the repository the first time, as bzr git-import will create it for us. This one command will import the entire repository including all of its branches. Subsequent calls to bzr git-import will simply update the repository.

Push changes back to bzr remote

cd <repo_name>.bzr-out/refs/heads/master
bzr push <bzr_remote>/master

Replace 'master' with for other branches.

changed August 10, 2009