#!/bin/bash WORK_TREE="/var/www/example" GIT_DIR="/var/repo/example.git" BRANCH="master" while read oldrev newrev ref do # only checking out the master (or whatever branch you would like to deploy) if [ "$ref" = "refs/heads/$BRANCH" ]; then echo "Ref $ref received. Deploying ${BRANCH} branch to production..." git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f $BRANCH cd $WORK_TREE chown -R www-data:www-data $WORK_TREE chmod -R 744 $WORK_TREE composer install else echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." fi done