Skip to content

Instantly share code, notes, and snippets.

@xperienced
Created January 10, 2016 19:12
Show Gist options
  • Save xperienced/46498b004b5e0003c299 to your computer and use it in GitHub Desktop.
Save xperienced/46498b004b5e0003c299 to your computer and use it in GitHub Desktop.
GIT update hook for git push to deploy
#!/usr/bin/env bash
readonly APP_NAME=test_app
readonly GIT_WORK_TREE=~/apps/$APP_NAME
declare REF_NAME=$1 COMMIT_HASH=$3
if [[ "$REF_NAME" == "refs/heads/master" ]]; then
echo "Master branch updated. Deploying to production."
mkdir -p $GIT_WORK_TREE
git --work-tree=$GIT_WORK_TREE checkout -f $COMMIT_HASH
else
echo "Pushing to branch other than master. Deployment is done only when pushing to master branch."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment