#!/bin/bash GIT_DIR="/home/developideas/project.git" TARGET="/home/developideas/project" BRANCH="master" PM2_NAME="Project" 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 'post-receive: Triggered.' cd $TARGET echo 'post-receive: git check out…' git --git-dir=$GIT_DIR --work-tree=$TARGET checkout $BRANCH -f echo 'post-receive: npm install…' npm install echo 'post-receive: → done.' pm2 restart -s $PM2_NAME echo 'post-receive: app started successfully with pm2.' else echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." fi done