So as I have been increasing movingly my life into Git version control it made sense to explore methods of publishing with Git.

Turns out to be quite simple.

On the web server

Create a folder to host live site (live)

mkdir live

Create a folder to host git repository (repo)

mkdir repo

Create git bare repository in folder (repo)

cd repo
git init --bare

Within the hooks folder create a file called post-receive

nano hooks/post-receive

with the following text

#! /bin/sh
GIT_WORK_TREE="../live" git checkout -f

Now ensure the folder live is writable by the web server and that the file post-receive is executable. This hooks means that when the repository is committed to it will check out the files to the live web directory.

On the local box

Now on the box that the files exisit all you need to do is add a new remote (I tend to call it web but it can be called anything).

git remote add web *your-remote-url*

and then when you push the files will be made live.