Git setup with hook for post-receive.

I have setup a simple git workflow.

In one directory on server I made bare repositroy

$ mkdir git-dir && cd git-dir
$ git init --bare

and in other one a folder for my live site

$ mkdir /var/www/www.example.com

then in the git-dir folder edit the post-receive hook

$ vi hooks/post-receive

and add this to file

#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f

after that, make this file excutable

$ chmod +x hooks/post-receive

In the /var/www/www.example.org we really dont have to put a git init or anything. This can be just plan files and they will be update anytime we push something to git-dir.

Also a big note is that user who runs git on server needs to have access to write to /var/www/www.example.org as if he doesnt, you will have a problem that code files on live site will not be updated.