Git for site deployment

On the remote:

$ mkdir website.git && cd website.git
$ git init --bare
Initialized empty Git repository in /home/user/website.git/

Define a post-receive hook:

$ cat > hooks/post-receive
GIT_WORK_TREE=/var/www/ git checkout --force
$ chmod +x hooks/post-receive

On the main site define a remote:

$ git remote add web ssh://
$ git config remote.web.push "+master:refs/heads/master"
$ git push web

Reference: Using Git to manage a web site by Abhijit Menon-Sen

Ian Bicking does not like this strategy and prefer to:

copy the working directory to a new location (minus .git/), commit that, and push the result to your deployment remote. You can send modified and untracked files, and you can run a build script before committing and push the result of the build script, all without sullying your “real” source control.

—Ian Bicking in this blog

He writed git-sync automating this task