Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. You can use these hooks for all sorts of reasons. (source https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
#!/bin/bash
#path to root directory of your project
TARGET="/home/project/dev"
#path to git bare repository
GIT_DIR="/home/project/project.bare"
BRANCH="develop"
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch..."
#git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
cd $TARGET
unset GIT_DIR
git pull
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done