Git Post-Receive push to live
If you have a remote GIT repository on the server hosting your live site, and want any push to the master
branch to be made live, here's a post-receive hook script to do so:
Place this script as post-receive
in the .git/hooks
folder of the repository on the remote machine:
#!/bin/sh
while read oldrev newrev ref
do
echo "# Analyzing $ref"
if [ "$ref" = "refs/heads/master" ]
then
echo '#'
echo '# Copying to live'
echo '#'
GIT_WORK_TREE='/path/to/doc/root' git checkout -f
fi
done
This will only copy updates pushed to the master
branch to the given /path/to/doc/root
folder, letting you keep several feature branches in the repository too, without interfering.
Written by MidnightLightning
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Script
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#