Skip to content

Instantly share code, notes, and snippets.

@gnrfan
Created March 3, 2016 22:31
Show Gist options
  • Save gnrfan/08242e4857481d07f828 to your computer and use it in GitHub Desktop.
Save gnrfan/08242e4857481d07f828 to your computer and use it in GitHub Desktop.
Git hook for deployment in production and staging environments
BRANCH="$1"
if [ $BRANCH == "refs/heads/master" ]; then
echo "Deploying changes to production environment."
GIT_WORK_TREE=/Users/gnrfan/code/git-tests/production-environment git checkout -f
elif [ $BRANCH == "refs/heads/staging" ]; then
echo "Deploying changes to staging environment."
GIT_WORK_TREE=/Users/gnrfan/code/git-tests/staging-environment git checkout -f
fi
@gnrfan
Copy link
Author

gnrfan commented Mar 3, 2016

At the server you create a repo somewhere with "git init /path/to/server/side/repo.git --bare" and then add this file in the hooks/ subfolder. You need to customize the steps for deploying in each environment as needed in your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment