Bazaar is a DVCS tool much like Git, and as a result it’s pretty straightforward to convert a Bazaar repository into a Git one.
To accomplish this, you’ll need to import the bzr-fastimport
plugin.
The procedure for installing the fastimport plugin is different on UNIX-like operating systems and on Windows.
In the first case, the simplest is to install the bzr-fastimport
package that will install all the required dependencies.
For example, with Debian and derived, you would do the following:
$ sudo apt-get install bzr-fastimport
With RHEL, you would do the following:
$ sudo yum install bzr-fastimport
With Fedora, since release 22, the new package manager is dnf:
$ sudo dnf install bzr-fastimport
If the package is not available, you may install it as a plugin:
$ mkdir --parents ~/.bazaar/plugins # creates the necessary folders for the plugins
$ cd ~/.bazaar/plugins
$ bzr branch lp:bzr-fastimport fastimport # imports the fastimport plugin
$ cd fastimport
$ sudo python setup.py install --record=files.txt # installs the plugin
For this plugin to work, you’ll also need the fastimport
Python module.
You can check whether it is present or not and install it with the following commands:
$ python -c "import fastimport"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named fastimport
$ pip install fastimport
If it is not available, you can download it at address https://pypi.python.org/pypi/fastimport/.
In the second case (on Windows), bzr-fastimport
is automatically installed with the standalone version and the default installation (let all the checkboxes checked).
So in this case you have nothing to do.
At this point, the way to import a Bazaar repository differs according to that you have a single branch or you are working with a repository that has several branches.
Now cd
in the directory that contains your Bazaar repository and initialize the Git repository:
$ cd /path/to/the/bzr/repository
$ git init
Now, you can simply export your Bazaar repository and convert it into a Git repository using the following command:
$ bzr fast-export --plain . | git fast-import
Depending on the size of the project, your Git repository is built in a lapse from a few seconds to a few minutes.
You can also import a Bazaar repository that contains branches. Let us suppose that you have two branches: one represents the main branch (myProject.trunk), the other one is the working branch (myProject.work).
$ ls
myProject.trunk myProject.work
Create the Git repository and cd
into it:
$ git init git-repo
$ cd git-repo
Pull the master branch into git:
$ bzr fast-export --export-marks=../marks.bzr ../myProject.trunk | \
git fast-import --export-marks=../marks.git
Pull the working branch into Git:
$ bzr fast-export --marks=../marks.bzr --git-branch=work ../myProject.work | \
git fast-import --import-marks=../marks.git --export-marks=../marks.git
Now git branch
shows you the master
branch as well as the work
branch.
Check the logs to make sure they’re complete and get rid of the marks.bzr
and marks.git
files.
Whatever the number of branches you had and the import method you used, your staging area is not synchronized with HEAD
, and with the import of several branches, your working directory is not synchronized either.
This situation is easily solved by the following command:
$ git reset --hard HEAD
Now let’s have a look at the files to ignore.
The first thing to do is to rename .bzrignore
into .gitignore
.
If the .bzrignore
file contains one or several lines starting with "!!" or "RE:", you’ll have to modify it and perhaps create several .gitignore
files in order to ignore exactly the same files that Bazaar was ignoring.
Finally, you will have to create a commit that contains this modification for the migration:
$ git mv .bzrignore .gitignore
$ # modify .gitignore if needed
$ git commit -am 'Migration from Bazaar to Git'