I had shared a precommit here which help you check your code before your commit. If you want to deploy it on test machine even production machine, you may need this.

You just change DEPLOY_ROOT and DEPLOY_ALLOWED_BRANCH variable. I suggest change DEPLOY_ALLOWED_BRANCH to dev instead of master if you deploy to test machine. Here is the code.

Put post-receive in hooks/ of your remote repo. Set executable to it with chmod u+x hooks/post-receive. Just type git push remote dev and enjoy it!