Skip to content

Instantly share code, notes, and snippets.

@seancheung
Created December 13, 2016 09:43
Show Gist options
  • Save seancheung/7ad04b2ab2e7e444d25e9ba1dbf4bed9 to your computer and use it in GitHub Desktop.
Save seancheung/7ad04b2ab2e7e444d25e9ba1dbf4bed9 to your computer and use it in GitHub Desktop.
git post receive hook
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
GIT_WORK_TREE=/path/to/website git checkout master -f
echo "password" | sudo -S chown -R git:www /path/to/website && sudo chmod -R 775 /path/to/website
cd /path/to/website/cache/folder
for DIR in `find . -mindepth 1 -maxdepth 1 -type d`
do
sudo rm -R -rf "$DIR"
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment