Lately, I’ve been using Git more and more for development, edging away from Subversion. One of the things I found slightly frustrating was setting up Redmine to sync the project repositories. Of course, this is easy in Subversion as it’s a remote call to the SVN server, however when using Git, a different approach is needed.

Essentially, what we need is a mirrored repository on the same file system as the Redmine installation, then using a sheduling task to fetch the updates.

For this guide, I’m going to assume you know how to install Git and Redmine and how to install and manage SSH keys so won’t cover these points. In my situation, I host all my repositories on my NAS which is a separate location to my Redmine installation.

For these examples, I am using Redmine v1.2.1 and Git 1.7.6 on Fedora 15.

First, initialize a new repository.

$ mkdir test.git
$ cd test.git
$ git --bare init

Next, create a directory inside your Redmine installation that will hold the mirrored repositories and clone the newly created Git repository.

$ cd /home/kevin/vhosts/redmine
$ mkdir repos
$ cd repos
$ git clone --mirror git@192.168.0.9:repos/test.git

Now, you need to create a new scheduled cron job to fetch all the changes. I personally do this at 5 minute intervals but alter it to suit your needs.

$ crontab -e

*/5 * * * * cd /home/kevin/vhosts/redmine/repos/test.git && git fetch -q --all

With all that done, you just need to set the repository path inside your Redmine project which in this case would be /home/kevin/vhosts/redmine/repos/test.git.

Advertisement