Convert bazaar to git

A while back, I decided I wanted to switch one of my projects to a public repository.  Something with a bug-tracker, a comment system, and that kind of stuff.  I also wanted to use a distributed version control system to make myself learn these new beasts.  I was torn between git and bazaar.  Then I ran into Brian Aker‘s post on forking Drizzle:  The point was not to get focused on if git or bazaar was better; but on the surrounding infrastructure.  So I put two of my projects on LaunchPad: matlab-bgl and libbvg.

Turns out he was right about the infrastructure.  It’s just that LaunchPad is a really bad infrastructure for a tool developed by mostly one person.  I realized that I just wasn’t pushing changes to these projects because launchpad was always really slow, and I didn’t really need any of its features.

However, I’ve frequently been using my GitHub repositories.  And so, a few years in, I wanted to port my repositories to GitHub instead.

Wow!  Was this much easier than I expected.

At first, I thought it’d be a nightmare.  If you search for “converting bazaar to git” you’ll get some pages with nasty tailor configurations.  For example:

After trying those techniques, I realized it didn’t port my branches at all.  Yuck, I want those branches!  After reading about how to convert branches, I found this link:

That link was wickly simple compared to the stuff using tailor.  Within minutes I had git repositories up with all branches intact!  A few notes: you don’t have to install fast-export via the plugin mechanism anymore.  Ubuntu has it built in.

sudo apt-get install bzr-fastexport

alias bzrexp="bzr fast-export"

mkdir matlab-bgl.git
cd matlab-bgl.git
git init --bare

bzrexp --export-marks=../marks.bzr ~/dev/matlab-bgl/master \
   | git fast-import --export-marks=../marks.git   
bzrexp --marks=../marks.bzr --git-branch=4.0 \
   ~/dev/matlab-bgl/4.0 | git fast-import \
   --import-marks=../marks.git --export-marks=../marks.git   
bzrexp --marks=../marks.bzr --git-branch=4.0-octave \
   ~/dev/matlab-bgl/4.0-octave | git fast-import \
   --import-marks=../marks.git --export-marks=../marks.git      
bzrexp --marks=../marks.bzr --git-branch=work \
   ~/dev/matlab-bgl/work| git fast-import \
  --import-marks=../marks.git --export-marks=../marks.git

git remote add <github repo location>
git push --all # push all branches

It turns out searching for “convert bzr to git” is much more fruitful than “convert bazaar to git”.  Hence, I’m naming this post “convert bazaar to git”

Now both of the projects are happily hosted on github with their history and branches intact!



This entry was posted in Code. Bookmark the permalink.

13 Responses to Convert bazaar to git

  1. Brian Aker says:


    Its funny, I hear people say that the connection to launchpad is slow, but I never seem to experience this myself. My work flow has me always keeping trees around locally to clone from so I rarely clone off of Launchpad.

    push() is never the slowest part of my workflow so I don’t really pay much attention to it. Compile/test is always what takes a bunch of time for me.


  2. iFred says:

    > sudo apt-get install bzr-fastexport
    Sure? Did you mean
    sudo apt-get install bzr-fastimport

  3. Pingback: YomGuy's Blog - Telemeta project now uses Git for development

  4. gcbenison says:

    Thanks for posting a solution to this problem. I was able to get it to work but by using ‘git init’ rather than ‘git init –bare’ … when does one need the ‘–bare’ option? Also – as a last step I had to run a ‘git checkout master’ in the new repository to get all the files to appear.

    • Florian says:

      You don’t /need/ the –bare option, but it significantly speeds things up because git doesn’t have to bother updating files in the working tree. These operations can be done purely on the repository, which is why they’re really fast in a bare repository.

  5. AstroFloyd says:

    Thanks! Interestingly, I found it through “bzr to git” 😉

  6. Pingback: Migrating from Bzr to Git (Single branch) « Short circuited tux_440volts !!

  7. Looks like iFred is correct: “sudo yum install bzr-fastimport” worked for me on Fedora 18.

  8. Jan says:

    i have to admit. its a shame that there is such a “fight” between two good systems. Anyway, evolution will remove bzr soon.

  9. m1st0 says:

    The following worked for me directly in Ubuntu 12.10:

    $ mkdir website.git
    $ cd website.git
    $ bzr init –format=git

    $ cd ../bazaar-website/
    $ bzr dpush ../website.git

    Using bzr log in the Bazaar repo and git log in the Git repo produced the equivalent output for each DVCS.

  10. There’s also a contrib setup for adding a bazaar (or hg) repo as a remote — pretty neat stuff!

  11. jakesyl says:

    This tutorial didn’t work for me, check out this one.. it was a breeze: !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s