I have the following post-receive hook I wrote on a virtual server such that it copies the dev and production versions of the repository into dev and production directories where each version of the site is run.
The following is the post-receive hook I wrote. How do I conditionally refresh just one or the other depending on what branch just got pushed?
#!/bin/sh
if [ -n $GIT_DIR ]; then
unset GIT_DIR
cd ..
fi
echo "Deploying to dev"
git checkout develop
umask 002 && git reset --hard
cp -r /path/to/git/files/* /path/to/dev/site/
echo "Deploying to prod"
git checkout master
umask 002 && git reset --hard
cp -r /path/to/git/files/* /path/to/prod/site/
Post-receive hooks receives on standard input 3 variables: old revision, new revision and ref name – which is exactly what you need. You can improve your script with:
And do some ifs depending on what refname contains (i.e: refs/heads/master).