Archive for the ‘Redmine’ tag
Setup a Git Repository for Redmine
Just installed Redmine for our project management / code tracking with Git. I must say it’s pretty nice being able to setup multiple projects easily (unlike Trac). The system is designed fairly well with a very user-friendly interface. And plus, it’s Rails !!
Anyways… too much on Redmine! This post is to describe how to setup a Git repository for use with Redmine.
The important thing to note is that the Git repository MUST BE on the same server as your Redmine setup. So, you probably need to have access to that server!
This was not ideal for me because our Git server does not have Ruby/Rails, etc. installed on it. That’s okay! You just need to clone the repository as a BARE repository on the same machine that your Redmine app is running on. Let’s see how:
Pick a place on your Redmine app server to house all your bare Git repos.
I will choose “/var/local/git_copies” for my example.
Note: Make sure that your permissions allow for your web-user to access these Git repos. My web-user is ‘build’.
# Change to build user (see above)
$ su - build
# Create the directory
$ mkdir /var/local/git_copies
Now, create your git clone as a bare repository clone.
Note: a bare repository will not have your actual files. It will just contain the standard git folders
# Goto your git_copies directory
$ cd /var/local/git_copies
# Make a bare clone of the repo
$ git clone --bare ssh://git@reposerver/usr/local/git_root/foo-project.git
Change into your project and configure remote branch tracking for your local copy.
$ cd foo-project.git
$ git remote add origin ssh://git@reposerver/usr/local/git_root/foo-project.git
Now, normally you want to sync up the repo, but you cannot do a normal git fetch && git merge into a bare repo.
Instead, do a fetch and reset the HEAD to point to the remote branch commit. You need the ‘–soft’ flag or else you will see errors!
$ git fetch origin
$ git reset --soft refs/remotes/origin/master
Now, remember you need to manually sync your new Git repo to have the changes appear on Redmine. A better idea would be to create a cronjob that does this automatically. Especially with more than 1 repository, automating this process will save much time. Here’s the basic idea:
# Add the following to your crontab
*/30 * * * * cd /var/local/git_copies/foo-project.git && git fetch origin && git reset --soft refs/remotes/origin/master > /dev/null
Instead of doing many times in your crontab, maybe it would be easier to setup a bash script to run:
#!/bin/bash
# Not tested! Use at your own risk, and change your GIT_ROOT and "*.git" to fit your setup.
GIT_ROOT=/var/local/git_copies
cd $GIT_ROOT
ls *.git | while read repo; do
cd $repo && git fetch origin && git reset --soft refs/remotes/origin/master > /dev/null && cd $GIT_ROOT
done
Then, just add this one script to your crontab and have it run every N minutes as you desire!
This site is helpful and worth checking out as well:
Reference on synchronizing 2 git repositories
That’s it, let me know how it goes!
