This is an old revision of the document!
Table of Contents
git
Iniciar repositorio en remoto
Given a project in our local file system:
/home/user/manhattan_project
1. Create the git repository:
git init /home/user/manhattan_project
2. Do the first commit
cd /home/user/manhattan_project git add * git commit -m "Initial commit"
3. Create the “bare” repository:
git clone --bare /home/user/manhattan_project /tmp/manhattan_project.git
4. Move the directory to its final location using SSH
scp -rv /tmp/manhattan_project.git user@git.example.com:/git/repositories/
Subir un cambio
git add <fichero> git commit -m "cambio realizado" git push
Servidor git acceso claves ssh
http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
0. (Opcional) Instalo paquetes
sudo aptitude install git
1. Crear usuario git con el minimo de permisos posible
sudo vim /etc/shells
Y anyadir, si no existe, la siguiente linea:
/usr/bin/git-shell
Seguimos con la creacion del usuario “git”:
sudo adduser git sudo chsh git
Teclear:
/usr/bin/git-shell
Y pulsar “enter”
sudo su git cd mkdir .ssh && chmod 700 .ssh touch .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys
2. Genero claves en el cliente y las subo al servidor
ssh-keygen -t rsa scp /home/user/.ssh/id_rsa.pub remote.example.com:/tmp
3. Volcar las claves:
sudo su git cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
Comandos sueltos
http://stackoverflow.com/questions/3258243/git-check-if-pull-needed
- To bring your remote refs up to date:
git remote update
- Will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
git status -uno
- Will show you the commits in all of the branches whose names end in master (eg master and origin/master).
git show-branch *master
- Subir tags a remoto
git push --tags origin
Hooks
Desplegar el contenido de un repositorio tras recibir un commit
1. Crear el hook 'post-receive' en el lado servidor:
sudo vim /srv/git/test.git/hooks/post-receive
Con el siguiente contenido:
#!/bin/sh git --work-tree=/srv/www/test --git-dir=/srv/git/test.git checkout -f
chmod +x /srv/git/test.git/hooks/post-receive
2. Hacer un commit
Resultado: el directorio “/srv/www/test” tendria que tener el contenido de del repositori “/srv/git/test.git” expandido
Enviar un correo tras recibir un commit
1. Crear el hook 'post-receive' en el lado servidor:
sudo vim /srv/git/test.git/hooks/post-receive
Con el siguiente contenido:
#!/bin/bash # Please adjust this setting RECIPIENTS="user1@example.com,user2@example.com" GIT="/usr/bin/git" SENDMAIL="/usr/sbin/sendmail" export USER_EMAIL=$($GIT log -1 --format=format:%ae HEAD) REPOSITORY=${PWD##*/} MAIL_CONTENT=`$GIT log --name-status HEAD^..HEAD` SUBJECT=$USER_EMAIL" updated git repo '"$REPOSITORY"'" $SENDMAIL "$RECIPIENTS" <<EOF subject:$SUBJECT from:$USER_EMAIL $MAIL_CONTENT EOF
chmod +x /srv/git/test.git/hooks/post-receive
2. Hacer un commit
Resultado: el directorio “/srv/www/test” tendria que tener el contenido de del repositori “/srv/git/test.git” expandido
GITHUB
Vamos a Settings “SSH and GPG keys” y añadimos la clave.