Using Gitolite with Redmine

2012-05-14 11:09:38 -0400

I use Gitolite to self-host multiple git projects and Redmine for time-tracking and project management. Redmine has a cool feature where it can integrate with source control management systems, but getting it to work with Gitolite was a bit of a challenge. Here's how I did it.

First, create a new repository in Gitolite. You're going to want to mirror a read-only version somewhere for Redmine to access. Then, we'll keep them synced using a post-receive hook in Git. After you create your new Gitolite repo, login to your server and go to a folder where you'll keep a mirror for Redmine. In this example, I'll use /var/gitolite-mirrors/</code>. In that folder, type this to create a mirror of your Gitolite repo and, critically, make git change the permissions of new files to 0644 (which gives read access to all users). Note that # means run as root.

# git clone --mirror /home/git/repositories/my-new-repo.git
# cd my-new-repo.git
# git config --add core.sharedRepository 0644</pre>
Now, change the permissions so that the git user (the user that Gitolite runs as) owns this folder.

# chown -R git:git ../my-new-repo.git</pre>
Finally, we'll add a post-receive hook to the Gitolite repo. Go to /home/git/repositories/my-new-repo.git/hooks</code>. Add a new file called post-receive</code>, and enter this into the file:

/usr/bin/git push --mirror /var/gitolite-mirrors/my-new-repo.git</pre>
Then, you'll want to change the ownership and permissions on that.

# chown git:git post-receive
# chmod 700 post-receive</pre>
In Redmine, go to your project you want to associate with this repo. Click the Settings, then Repository tabs. Choose Git as your SCM. In this example, you'd enter /var/gitolite-mirrots/my-new-repo.git</code> as your repository path. Click "Save".

Now, click the Repository tab on the top tab bar. You may get a 404 error at this point. That is because you need to push a master branch to this repository (it is empty right now). Push a few files to the repo and check again.

If it is still not working, you can log in to your server and navigate to the mirror location (/var/gitolite-mirrors/my-new-repo.git</code>). Switch users to the user your Redmine process is running as (probably www-data or something similar). Redmine is running git log master</code> to get the changes from your repo to display on the webpage. Try running that command and see if you get any errors, and debug from there.