HowTo keep in sync your git repository for redmine » History » Version 8

Joon Ro, 2012-07-05 17:47
Reorganized post so the instructions with recent git comes first. It would be easier for readers to find relevant info.

1 1 Thomas Lecavelier
h1. HowTo keep in sync your git repository for redmine
2 1 Thomas Lecavelier
3 8 Joon Ro
h2. With sufficiently recent git (>=1.6.0)
4 8 Joon Ro
5 8 Joon Ro
_In the below examples, "git_user" and "project.git" should be modified for your GitHub project_
6 8 Joon Ro
<pre>
7 8 Joon Ro
git clone --mirror git@github.com:git_user/project.git
8 8 Joon Ro
</pre>
9 8 Joon Ro
 
10 8 Joon Ro
then install a crontask
11 8 Joon Ro
<pre>
12 8 Joon Ro
sudo vi /etc/cron.d/sync_git_repos
13 8 Joon Ro
*/5 * * * * app cd /path/to/project.git && git fetch -q --all
14 8 Joon Ro
</pre>
15 8 Joon Ro
_*/5 in the last line defines the minute at which the synchronization takes place, for example, */2 would cause the sychronization to take place every two minutes. */5 causes the synchronization to take place on minutes divisible by 5 (5, 10, 15, etc.)_
16 8 Joon Ro
17 8 Joon Ro
h2. With older git
18 8 Joon Ro
19 1 Thomas Lecavelier
Here is a HowTo written by Farzy ("Farzad FARID":http://www.pragmatic-source.com/) that explains how to keep two git repositories syncronized
20 1 Thomas Lecavelier
21 1 Thomas Lecavelier
* "Automatic synchronization 2 git repositories [en]":http://www.pragmatic-source.com/en/opensource/tips/automatic-synchronization-2-git-repositories
22 2 Jim Mulholland
* "Synchronisation automatique de deux référentiels git [fr]":http://www.pragmatic-source.com/fr/opensource/tips/synchronisation-automatique-de-deux-referentiels-git
23 3 Eddie Ringle
24 2 Jim Mulholland
*Summary Of Above Blog Posts*
25 2 Jim Mulholland
26 2 Jim Mulholland
<pre>
27 1 Thomas Lecavelier
git clone --bare git@github.com:git_user/project.git project.git
28 2 Jim Mulholland
cd project.git
29 3 Eddie Ringle
git remote add origin git@github.com:git_user/project.git
30 4 Alexey Trofimenko
git fetch -v
31 6 Alexey Trofimenko
git fetch origin
32 4 Alexey Trofimenko
git reset --soft refs/remotes/origin/master 
33 4 Alexey Trofimenko
</pre>
34 4 Alexey Trofimenko
35 4 Alexey Trofimenko
_In this cron script, "app" is the owner of the project.git directory_
36 4 Alexey Trofimenko
<pre>
37 4 Alexey Trofimenko
sudo vi /etc/cron.d/sync_git_repos
38 1 Thomas Lecavelier
# One-way synchronization of a local and remote bare Git repository.
39 6 Alexey Trofimenko
# Repeat this line for each repository.
40 7 Philippe Creux
*/5 * * * * app cd /path/to/project.git && git fetch origin && git reset --soft refs/remotes/origin/master > /dev/null
41 4 Alexey Trofimenko
</pre>