Skip to content

Instantly share code, notes, and snippets.

@Chapoton
Created September 25, 2019 03:11
Show Gist options
  • Save Chapoton/45868220855f4df5327720e224d345f0 to your computer and use it in GitHub Desktop.
Save Chapoton/45868220855f4df5327720e224d345f0 to your computer and use it in GitHub Desktop.
Server-side hook for running scripts associated with auto deployments
#!/bin/sh
#
# Server-side hook for running scripts associated with auto deployments.
#
# Reference:
# http://nicolasgallagher.com/simple-git-deployment-strategy-for-static-sites/
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
#
# To enable this hook, rename this file to "post-receive".
# assign working directory
# this hook lives within your example.git directory
# this is where you will push the build assets to, from your local machine
# you don’t want the files served here
WEB_DIR=/path/to/example.com
# remove any untracked files and directories
# https://git-scm.com/docs/git-clean
git --work-tree=${WEB_DIR} clean -fd
# if you need to exclude some files from being cleaned out by Git (e.g., a .htpasswd file)
# you can do that using the --exclude option
# this requires Git 1.7.3 or above to be installed on your server
# to enable, uncomment and update.
# git --work-tree=${WEB_DIR} clean -fd --exclude=<pattern>
# force checkout of the latest deploy
# https://git-scm.com/docs/git-checkout
git --work-tree=${WEB_DIR} checkout --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment