From Svn to Gitolite
Today I’d like to describe how to migrate from Svn to Git, minding existing infrastructure. One of the most common Subversion servers configurations is Linux server with Apache and mod_dav_svn module serving one or more Subversion repositories. Each Subversion repository may contain one or more projects. Of course, I will use SubGit to make migration smooth, i.e. without a need to force users to make a switch from Subversion to Git overnight.
For Git, I’ve chosen Gitolite as a Git management tool, as it is relatively easy to install and lot of documentation resources.
Here is the first picture. In blue initial configuration is shown and in gray are what we will gradually build in this post. This sample migration takes place on Ubuntu Linux server:
Step 1: Install Gitolite and create ‘Git’ user
To install Gitolite I’m using “install as root” method from Gitolite documentation. Few migration-specific additions are marked with the bold font.
On your workstation:
- copy your ~/.ssh/id_rsa.pub file to /tmp/YourName.pub on the server. (The name of this file determines your gitolite username, so if you leave it as id_rsa.pub, your gitolite username will be id_rsa, which may not be what you want).
On your server, as root:
git clone git://github.com/sitaramc/gitolite gitolite/src/gl-system-install # defaults to being the same as: # gitolite/src/gl-system-install /usr/local/bin /var/gitolite/conf /var/gitolite/hooks
To upgrade gitolite, repeat the above commands. Make sure you use the same arguments for the last command each time.
Git user should be in the same group as your Apache user:
useradd git -g www-data -m -s /bin/bash
Switch to the hosting user
su - git
(now as git)
When prompted edit the following values in /home/git/.gitolite.rc file:
$REPO_UMASK = 0002; # default is 0077 $GL_GITCONFIG\_KEYS = "core.sharedRepository"; # default is ""
Change repositories directory permissions to let Apache user read it contents:
chmod ug+rx /home/git/repositories
On your workstation:
git clone git@server:gitolite-admin
Step 2: Create Git repositories with Gitolite
Create empty Git repository for each of your Subversion project. In this post I assume that there are three Subversion projects in a single Subversion repository (p1, p2, p3) each with a standard trunk/branches/tags layout. You may have different distribution as well as different layout.
On your workstation, edit gitolite-admin/conf/gitolite.conf file:
repo gitolite-admin RW+ = alex repo testing RW+ = @all repo p1 RW+ = alex config core.sharedRepository = true repo p2 RW+ = alex config core.sharedRepository = true repo p3 RW+ = alex config core.sharedRepository = true
Add more access rules if necessary, commit and push your change:
git add conf/gitolite.conf git commit -m "repositories added" git push
Step 3: Set up smooth Svn to Git migration
On server download and install SubGit. Use either debian package distribution or zip archive.\
sudo dpkg -i subgit_1.0.0-EAP-902_all.deb
To set up migration, as www-data user, run:\
$ sudo -u www-data subgit configure /var/svn/repos SubGit version 1.0.0-EAP ('Miai') build #902 This is an EAP build, which you may not like to use in production environment. Detecting paths eligible for translation... Subversion to Git mapping has been configured in '/var/svn/repos':\ /p1 : /var/svn/repos/git/p1.git /p2 : /var/svn/repos/git/p2.git /p3 : /var/svn/repos/git/p3.git
Adjust ‘/var/svn/repos/conf/subgit.conf’ file and then run
subgit install "/var/svn/repos"
to complete SubGit installation.
SubGit has detected Subversion projects and created default configuration. Now I will edit SubGit configuration file at /var/svn/repos/conf/subgit.conf to specify our Gitolite repositories locations instead of default ones and to mark repository as shared:
[core] # shared option must be set to 'true', # as long as apache and gitolite are ran # by different users (i.e. www-data and git) shared = true ... # authors.txt consists of mapping lines: # svnUser=gitUser<gitUser@email.com> # this file is optional authorsFile = conf/authors.txt [git "p1"] translationRoot = p1 repository = /home/git/repositories/p1.git .... [git "p2"] translationRoot = p2 repository = /home/git/repositories/p2.git ... [git "p3"] translationRoot = p3 repository = /home/git/repositories/p3.git ...
As soon as you’re happy with configuration, enable migration:
$ sudo -u www-data subgit install /var/svn/repos SubGit version 1.0.0-EAP ('Miai') build #902 ... INSTALLATION SUCCESSFUL ...
That’s all, Gitolite and smooth Svn To Git migration is now configured!
Commit changes to Subversion and Git users will pull them into their Git clones, push commits to Git repository and Subversion users will receive them. Try it
In case you have any questions or suggestions, please feel free to contact me at email@example.com Thanks!