Skip to content

Instantly share code, notes, and snippets.

@dipnlik
Created October 3, 2011 20:09
Show Gist options
  • Save dipnlik/1260096 to your computer and use it in GitHub Desktop.
Save dipnlik/1260096 to your computer and use it in GitHub Desktop.
Post-receive hook to deploy projects by simply pushing to the repository
#!/bin/bash
# Don't forget to check environments and deploy paths before using this script.
function deploy {
echo "INFO: Deploying to $environment environment."
mkdir -p $DEPLOY_PATH
GIT_WORK_TREE=$DEPLOY_PATH git checkout -f $environment
}
while read oldrev newrev refname; do
# turns 'refs/heads/branchname' into 'branchname'
environment=${refname##*/}
case "$environment" in
( "production" )
DEPLOY_PATH=/path/to/myproject
deploy ;;
( "homolog" )
DEPLOY_PATH=/path/to/myproject-homolog
deploy ;;
( "" )
echo "ERROR: Unspecified environment name. No deploy was made." ;;
( * )
echo "WARNING: Environment '$environment' is not set up. No deploy was made." ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment