This walks through how I push changes to my remote Git server and update my live website with a single command.
The local repository
It doesn't matter how the local repository is set up, but for the sake of argument, let's suppose you're starting one from scratch.
mkdir website && cd website
echo 'Hello, world!' > index.html
git add index.html
git commit -q -m "The humble beginnings of my web site."
The remote repository
This assumes the website is hosted on a server you can reach over SSH, and that you can SSH in without typing a password each time.
On the server, create a new repository to mirror the local one:
cd /home/project/
mkdir website.git && cd website.git
git init --bare --shared
# Initialized empty Git repository in /home/project/website.git/
Then define (and enable) a post-receive hook that checks out the latest tree into the web server's DocumentRoot:
mkdir /var/www/www.example.org
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org
git checkout -f
chmod +x hooks/post-receive
Back on the workstation, define a name for the remote mirror, then push to it, which creates a new master branch there:
git remote add web ssh://[email protected]/home/project/website.git
git push web master
From here, one command pushes to the remote repository and updates the webserver's DocumentRoot at the same time:
git push web