Skip to content

Instantly share code, notes, and snippets.

@phsacramento
Created July 23, 2013 18:38
Show Gist options
  • Save phsacramento/6064966 to your computer and use it in GitHub Desktop.
Save phsacramento/6064966 to your computer and use it in GitHub Desktop.
# ###############
# SETUP LOCAL
# ###############
cd $LOCAL/$SITE
git init
git config color.branch auto
git config color.diff auto
git config color.interactive auto
git config color.status auto
# Gitignore básico
cat >> .gitignore <<EOF
*.~
*.*~
*.swp
.DS_Store
.buildpath
.project
.settings
.bash_history
.bash_logout
.bash_profile
.bashrc
.ftpquota
.gemrc
.ssh/
logs/
tmp/
cache/
EOF
git add .
git commit -m "Primeiro commit"
# ##################
# SETUP REMOTO - SSH
# ##################
ssh $USUARIO@$HOST
mkdir ~/.ssh
exit
# Se você nunca rodou o ssh-keygen, faça isso agora
# ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub | ssh $USUARIO@$HOST 'cat >> ~/.ssh/authorized_keys'
# ##################
# SETUP REMOTO - GIT
# ##################
ssh $USUARIO@$HOST
cd /var/www/$SITE
git init # sem --bare :)
# Adiciona cores ao git
git config color.branch auto
git config color.diff auto
git config color.interactive auto
git config color.status auto
cat >> .git/hooks/post-receive <<EOF
#!/bin/sh
unset GIT_DIR
unset GIT_WORK_TREE
export GIT_DIR="/var/www/$SITE/.git"
export GIT_WORK_TREE="/var/www/$SITE"
echo "=> Atualizando website remoto"
git checkout -f
echo "=> PRONTO! Agora você pode ver as alterações no website remoto..."
EOF
chmod +x .git/hooks/post-receive
exit
# ###############
# PRIMEIRO DEPLOY
# ###############
cd $LOCAL
git remote add web ssh://$USUARIO@$HOST//var/www/$SITE/.git
# Se for exibida um mensagem de erro, no servidor remoto, execute
# git config receive.denycurrentbranch 'ignore'
git push web +master:refs/heads/master
# #######################
# DEPLOY
# #######################
# REMOTO
ssh $USUARIO@$HOST
# Se tiver alguma alteração, descarta ou faz o commit delas
git status
exit
# LOCAL
git fetch web
git checkout --track -B remote web/master
git checkout master
git merge remote
# Fast Way:
# git checkout --track -B remote web/master && git checkout master && git merge remote
# Envia as atualizações para o servidor remoto
git push web
# Se nenhuma mensagem for exibida, execute o comando abaixo
# no servidor remoto para forçar a atualização do branch:
# git checkout -f
# Se for exibida um mensagem de erro, no servidor remoto, execute
# git config receive.denycurrentbranch 'ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment