Saturday, July 9, 2011

Converting bzr repositories to git

After using Bazaar for some projects and Git for others, I decided to stay on Git, mainly for speed and github.

Here's what I did to convert my bzr repositories to Git, keeping history:

Install bzr-fastimport from your package manager or, if you're not on GNU/Linux, download it from http://wiki.bazaar.canonical.com/BzrFastImport.

Create your new Git repository
$ git init project_git
$ cd project_git
view raw bzr_to_git_1.sh hosted with ❤ by GitHub

Copy the history
$ bzr fast-export ../project_bzr | git fast-import
view raw bzr_to_git_2.sh hosted with ❤ by GitHub

Do a checkout to get the files. Git will act like nothing happend, but ls before and after will tell you otherwise
$ git checkout master
view raw bzr_to_git_3.sh hosted with ❤ by GitHub

If you used bzr ignore, rename the list so it will be used by Git
$ mv .bzrignore .gitignore
view raw bzr_to_git_4.sh hosted with ❤ by GitHub

You could do a commit to mark the change. If you didn't rename .bzrignore, you'll have to force it:
$ git commit --allow-empty
view raw bzr_to_git_5.sh hosted with ❤ by GitHub

If this isn't a one-shot conversion and you need to update the Git repository again, you can use marks so only new changes are exported. Read the comments on this page for a short tutorial.

No comments:

Post a Comment