Skip to content

Instantly share code, notes, and snippets.

@rfreebern
Created September 28, 2011 18:11
Show Gist options
  • Save rfreebern/1248724 to your computer and use it in GitHub Desktop.
Save rfreebern/1248724 to your computer and use it in GitHub Desktop.
git post-receive hook for atomic deployment
On server:
mkdir -p ~/deploy/mysite.git && cd $_
git init --bare
(place the post-receive file in hooks/post-receive)
mkdir -p /var/www/mysite
Make sure your virtual host's DocumentRoot is set to /var/www/mysite/live
On development machine:
git remote add deploy ssh://username@server/home/username/deploy/mysite.git
git push deploy master
#!/bin/sh
PRODUCTION_DIR=/var/www/mysite
LATEST_REV=`git rev-parse HEAD`
DEPLOY_TIMESTAMP=`date +%Y-%m-%d-%H-%M-%S`
mkdir $PRODUCTION_DIR/$DEPLOY_TIMESTAMP-$LATEST_REV
GIT_WORK_TREE=$PRODUCTION_DIR/$DEPLOY_TIMESTAMP-$LATEST_REV git checkout -f
ln -sf $PRODUCTION_DIR/$DEPLOY_TIMESTAMP-$LATEST_REV $PRODUCTION_DIR/live
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment