Are you a developer? Do you use GitHub to host your repo? Last question, do you use Redmine to manage your projects? It does not really matter if you answer those questions or not, I am going to write this how-to anyway. I needed a way to use my GitHub repo with our Redmine install at http://code.idlesoft.net/, so I started googling for answers. After finding numerous pages that just told me to quit and host a git server myself, I came up with my own solution. (AFAIK, Git server’s are a real pain if you don’t do the procedure perfectly) The answer is your friendly neighborhood Cron service. Now if you do not run Linux then sorry, I can not help you. Anyways, here’s the how-to.
First you need to clone the repo you want to link with Redmine, do this by typing the following in the linux console (I am using /var/git/repos as the parent directory for my git repos, you can choose something different):
cd /var/git/repos git clone email@example.com:yourname/projectname.git
You may have to create that parent directory first, you may also need root access depending on your server setup.
Make sure the user that Redmine runs under (usually the same as the HTTP user) has read and write permissions (I just make the web user the owner, it’s the easiest). For me, that user is www-data:
chown -hR www-data:www-data /var/git/repos/
Next, you’ll need to edit the web user’s crontab, get root permissions and type the following:
crontab -u www-data -e
You will see a text editor window open and, depending on whether the user’s crontab has been modified before, lines with cron commands. Do not worry if there is already text in there, as it is unimportant. Create a new line and type the following:
*/2 * * * * cd /var/git/repos/projectname && git pull >> /dev/null
Let me explain each part of that line:
*/2 * * * *
The above tells cron to perform the command every two minutes of every hour, of every day, of every month (so, every two minutes)
cd /var/git/repos/projectname && git pull >> /dev/null
This is the command that cron will perform. Change into the project directory and pull the latest code from github. The “>> /dev/null” means to throw out all the output, which we don’t want to see. If you do want to see that output, change /dev/null to the path of a log like “/home/bob/git.log”.
Now in Redmine, go to your project’s settings and click on the Repository tab. Select Git from the drop-down and for the path, enter in the path to your project repo, with /.git/ appended to the end, so:
Save it, and you are done! Check out your repository on the Repository tab of your project.
One more thing, you’ll need to make sure permissions are set each time you add a new repo.