Mirror of the Rel4tion website/wiki source, view at <http://rel4tion.org>

[[ 🗃 ^yEzqv rel4tion-wiki ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/yEzqv

SSH: git clone USERNAME@vervis.peers.community:yEzqv

Branches

Tags

master :: maint / admin / Git_Server /

Mirrors.mdwn

Sometimes it’s useful to have a repository on your server, which simply mirrors some other repository, on another server. Maybe it’s easier for you to work with it like that, and create forks. Or the repository you want to use it hosted on a problematic server, e.g. a centralized hosting service, and you want to make the code available on an independent 100% free software powered system.

General Procedure

In general, when creating a local personal mirror outside of Gitolite, the following procedure works.

Create the repo:

git init --bare

Configure it:

git remote add origin URL-HERE
git config remote.origin.fetch +refs/*:refs/*
git config fetch.prune true

Run every hour/day/week to update the mirror:

git fetch --quiet origin

G1thub

However, Github has additional refs for pull requests, which can create a lot of unnecessary clutter and increase repo size.

The following approach avoid them. However, it misses some namespaces git uses, such as notes and replacements. Most of the time they’re not used anyway so I guess it’s reasonable. Also, personally, most of the time I don’t interact with Github. Anyway these namespaces can be added manually to the configuration if needed.

The commands would be as follows.

Create the repo:

git init --bare

Configure it:

git remote add origin URL-HERE
git config remote.origin.fetch +refs/heads/*:refs/heads/*
git config --add remote.origin.fetch +refs/tags/*:refs/tags/*
git config fetch.prune true

Run every hour/day/week to update the mirror:

git fetch --quiet origin

Gitolite

Now let’s see how it’s done on a gitolite server.

Create new empty repo (through gitolite-admin, as described in the previous sections of this guide).

Become the git user (# su - git), go to the repository (cd /home/git/repositories/my-mirror.git) and apply the configuration commands on it as listed above (you can use the G1thub specific ones if you mirror a G1thub repo).

Write a simple mirror.sh script to run the periodic update command:

#!/bin/bash

BASE=/home/git/repositories

cd $BASE/my-mirror.git
git fetch --quiet origin

If you have several mirrors, you can extend the script to loop over them and run the git fetch command for each. Example:

#!/bin/bash

BASE=/home/git/repositories
EXT=.git

MIRRORS="
	bicon
	4store
	raptor
	rasqal
	librdf
	redland-bindings
	redlandpp
"

for repo in $MIRRORS
do
	cd ${BASE}/${repo}${EXT}
	git fetch --quiet origin
done

Another option is to go over all repositories, and use git-config to determine whether a repository is a mirror, e.g. by checking whether gitweb.category begins with “Mirror”. But then you nee to make sure you assign gitweb categories consistently.

Now become the git user and setup a cron job to run the script periodically (crontab -e -u git):

# mail any output to `joe', no matter whose crontab this is
MAILTO=joe
# m h dom mon dow command
# run at 4 AM every day
00 04 * * *       /home/git/mirror.sh

crontab opens your default text editor (e.g. nano or vim) and lets you add the new job. Simply append it to the end of the file.

If you never used nano or vim - maybe it’s time to learn, at least the basics. nano is quite simple: Ctrl-O saves, Ctrl-X quits. To learn the basics of vim, try vimtutor. For simple use it’s enough to learn how to insert and delete text, how to save and how to quit. Summary:

Of course you can make Gedit or Kate etc. your default text editor, but then you’ll be clueless when working on a GUI-less server or using SSH or when things crash. It’s good to have a basic tool which is always available.

If you want to read the e-mail sent to you (user joe) by cron, add a “local mbox” account to your e-mail client, and configure it to read from the file /var/mail/joe.

[See repo JSON]