====== Git ======
Git est un gestionnaire de versions (comme svn, cvs ou d'autres) décentralisé.
Un résumé des commandes chez [[http://doc.fedora-fr.org/wiki/Gestion_et_contr%C3%B4le_de_versions_avec_Git|fedora]] et le [[http://book.git-scm.com/index.html|git community book]] ainsi que le [[http://progit.org/book/|pro git book]] et sa [[http://progit.org/book/fr/|traduction française]]
Mais, parfois, la centralisation s'avère pratique, et c'est aussi possible.
Cf http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way,
http://www.nikrou.net/post/2009/02/20/Mettre-en-place-un-d%C3%A9p%C3%B4t-central-git ou http://blog.touv.fr/2009/06/depot-git-prive-et-personnel-sur.html pour l'install du dépot central.
Ensuite, quelques liens utiles
* http://linux-attitude.fr/post/Git-%C3%A0-tous-les-%C3%A9tages
* http://jonas.nitro.dk/git/quick-reference.html
* http://cheat.errtheblog.com/s/git
* http://alexgirard.com/git-book/3_workflows_distribu%25C3%25A9s.html
* http://xhfamily.com/x/notes/20080819_git-process.html
Pour créer un dépôt centralisé avec gitosis :
* http://www.siteduzero.com/tutoriel-3-187504-heberger-des-depots-git-avec-gitosis.html
* http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
===== Opérations courantes =====
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#git-quick-start
# transformer le dossier courant en projet git
git init
# ajouter tous ses fichiers au projet (ou bien préciser les fichiers à ajouter)
git add .
# ajouter un alias pour un projet sur un serveur distant
git remote add alias_de_ce_projet_sur_ce_serveur user@:path/2/le_projet.git
# y envoyer les fichiers
git push alias_de_ce_projet_sur_ce_serveur la_branche # "master" pour la branche principale
# commit d`un fichier (localement)
git commit -m 'message de commit' le_fichier
# commit de tous les fichiers (localement)
git commit -m 'message de commit' -a
# envoi de tous les derniers commit (depuis le dernier push) sur le serveur
git push
==== Ajout d'un dépôt local sur le serveur ====
Pour créer le dépôt, faut d'abord modifier gitosis.conf pour lister le nouveau repository sur la ligne
writable du group qui va bien (pour déclarer qui aura le droit d'écrire sur ce dépôt). Et pour modifier ce gitosis.conf
# Si ce n'est déjà fait on récupère une copie localement (coté client donc)
git clone git@:gitosis-admin.git # on suppose que git est le user du server qui permet d'accéder aux dépôts)
cd gitosis-admin
joe gitosis.conf
# ensuite on envoie ce fichier
git commit -m 'ajout du dépot machintruc' gitosis.conf
git push
# et on peut balancer notre nouveau projet qui existe localement
cd /path/2/mon_projet
# si le dépot local git n'existe pas on le créé
git init
# on ajoute tous les fichiers (mais on pourrait n'en préciser que certains seulement)
git add .
git commit -a -m 'Premier commit'
# on créé le dépot distant (on a déjà déclaré mon_projet dans gitosis.conf tout à l'heure), on l'appelle origin
git remote add origin git@:.git
# et on envoie sur le depot origin notre branche locale master
git push origin master
# pour les push suivant, on pourra faire un simple "git push"
==== Rendre un dépôt public ====
Pour que des anonymes puissent cloner un dépôt, il faut dire à git-daemon qu'il peut l'exporter en lecture seule sans vérifier les clés ssh avec
cd
touch /git-daemon-export-ok
# et pour retirer ces droits de lecture anonyme il suffit d'effacer ce fichier vide.
===== Script de démarrage =====
Mon script d'init /etc/init.d/git-daemon (basé sur /etc/init.d/skeleton)
#!/bin/sh
### BEGIN INIT INFO
# Provides: git-daemon
# Required-Start: $networking
# Required-Stop: $networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start/stop git-daemon to handle git protocol
# Description: The daemon is launched under the git user
### END INIT INFO
# Author: Daniel Caillibaud
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="git-daemon (which handles git protocol on 9418 port)"
NAME=git-daemon
DAEMON=/usr/bin/$NAME
# DAEMON_ARGS later (after default conf load)
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# start-stop-daemon options
SSD_OPTIONS='--chuid git:git --nicelevel 5 --background' # git-daemon doesn't detach himself
# Exit if the package is not installed
[ ! -x "$DAEMON" ] && log_daemon_msg "$DAEMON doesn't exist" && echo "$DAEMON doesn't exist" > 2 && exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS="--base-path=$GIT_REPOSITORIES" # GIT_REPOSITORIES is in /etc/default/git-daemon
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon $SSD_OPTIONS --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon $SSD_OPTIONS --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 3
;;
esac
Avec les prefs
echo 'GIT_REPOSITORIES=/home/git/repositories/' > /etc/default/git-daemon
Mais tout ça sert pas à grand chose car il y a un paquet git-daemon-run, qui, comme son nom l'indique...
Bref, ce qui suit va quand même plus vite
aptitude install git-daemon-run
ln -s /usr/bin/sv /etc/init.d/git-daemon
# et on va modifier /etc/sv/git-daemon/run pour préciser le --base-path