Skip to content

Instantly share code, notes, and snippets.

@eamexicano
Created September 24, 2012 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eamexicano/3776443 to your computer and use it in GitHub Desktop.
Save eamexicano/3776443 to your computer and use it in GitHub Desktop.
Inicializa repositorio de git. Lo envia vía ssh a un nuevo repositorio vacío y sincroniza con htdocs. Necesita el nombre del repo, usuario y modificar las rutas.
#!/bin/bash
SITIO="$1"
USUARIO="$2"
PUERTO="22"
REPOSITORIO_REMOTO="/var/repo/$SITIO"
SHEBANG="#!/bin/bash"
SITIO_HTDOCS="/var/www/$SITIO"
read -r -d '' HOOK <<EOF
${SHEBANG}
echo ' * * * Actualizando $SITIO_HTDOCS * * * '
GIT_WORK_TREE=$SITIO_HTDOCS git checkout -f
echo ' * * * ¡ Hecho ! * * * '
EOF
# Repositorio local
git init
echo ".DS_Store" > .gitignore
git add .
git commit -m "Repositorio local inicializado"
# Repositorio Remoto
ssh -p $PUERTO $USUARIO "mkdir -m 0775 $SITIO_HTDOCS; mkdir $REPOSITORIO_REMOTO; cd $REPOSITORIO_REMOTO; git init --bare; echo \"$HOOK\" > $REPOSITORIO_REMOTO/hooks/post-receive; chmod +x $REPOSITORIO_REMOTO/hooks/post-receive; exit;"
wait
# Repositorio local
git remote add origin ssh://$USUARIO:$PUERTO$REPOSITORIO_REMOTO
git push origin +master:refs/heads/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment