Configure hook/post-receive to checkout the current branch automatically

#!/bin/bash

while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
GIT_WORK_TREE=/var/www/vhosts/website/htdocs git checkout -f $branch
done