See https://ecoconsulting.co.uk/solutions/#deploy-a-website-to-a-server-using-git
Or the (very similar) setup I have for my own web site. web/denisdefreyne.com.git/hooks/post-receive:
#!/bin/bash
set -ex
TARGET="/var/www/virtual/defreyne/denisdefreyne.com"
GIT_DIR="/home/defreyne/web/denisdefreyne.com.git"
BRANCH="built"
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch on server..."
git --work-tree="${TARGET}" --git-dir="${GIT_DIR}" checkout -f ${BRANCH}
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
See https://ecoconsulting.co.uk/solutions/#deploy-a-website-to-a-server-using-git
Or the (very similar) setup I have for my own web site.
web/denisdefreyne.com.git/hooks/post-receive: