Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.
I am now
With a few setup steps you can easily deploy changes to your website using a one-liner like
git push production
Which is nice and simple, and you don't have to log into the remote server and do a pull or anything. Note that this will work best if you don't use your production checkout as a working branch! (The OP was working within a slightly different context, and I think @Robert Gould's solution addressed it well. This solution is more appropriate for deployment to a remote server.)
First you need to set up a bare repository somewhere on your server, outside of your webroot.
mkdir mywebsite.git
cd mywebsite.git
git init --bare
Then create file hooks/post-receive
:
#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
And make the file executable:
chmod +x hooks/post-receive
On your local machine,
git remote add production git@myserver.com:mywebsite.git
git push production +master:refs/heads/master
All set! Now in the future you can use git push production
to deploy your changes!
Credit for this solution goes to http://sebduggan.com/blog/deploy-your-website-changes-using-git/. Look there for a more detailed explanation of what's going on.