Ce que "bare" signifie
Un dépôt bare contient seulement les contenus de .git — pas d'arbre de travail, pas de checkout. C'est ce vers quoi vous pushez et depuis quoi vous clonez.
En créer un
mkdir myproject.git
cd myproject.git
git init --bare
Pusher dessus
cd ~/work/myproject
git remote add origin /path/to/myproject.git
git push -u origin main
Partager sur un serveur
scp -r myproject.git user@server:/srv/git/
chgrp -R devs /srv/git/myproject.git
chmod -R g+rwX /srv/git/myproject.git
find /srv/git/myproject.git -type d -exec chmod g+s {} +
# /srv/git/myproject.git/config
[core]
sharedRepository = group
git init --bare --shared=group myproject.git
Cloner
git clone user@server:/srv/git/myproject.git
SSH versus HTTP
Pour les petites équipes, l'accès SSH plus git-shell donne une configuration propre et sécurisée.
Outils self-hosting
Pour plus de quelques dépôts, lancez Gitea, Forgejo, GitLab Community Edition ou similaire.
Mirrors et backups
git clone --mirror <url> backup.git
cd backup.git
git remote update --prune
Hooks côté bare
# /srv/git/myproject.git/hooks/post-receive
#!/usr/bin/env bash
while read old new ref; do
if [ "$ref" = "refs/heads/main" ]; then
cd /srv/www/myproject &&
git --git-dir=. fetch /srv/git/myproject.git main &&
git --git-dir=. reset --hard FETCH_HEAD
fi
done