Using Git to deploy code changes..

Submitted by fago on Tue, 03/30/2010 - 12:14
Wouldn't it be nice have your changes up and running at a development site just by pushing it there with git push dev? Well with Git that's pretty easy to achieve. First create a new Git repository on the remote if you haven't yet:
mkdir www
cd www
git init
Then push your code to this repository initially and then check it out:
git checkout your-branch
So now we need to make Git automatically checking out the latest code once you pushed it in. For that create the script ".git/hooks/post-receive":
cd ..
export GIT_DIR=".git"
git checkout -f
And don't forget to make the file executable. Now as the code is automatically updated, we need to disable the usual warning when one pushes to a remote repository with a checkout:
git config receive.denycurrentbranch ignore
That's it. Simple and useful, not? :) Credits go to, which I used to come up with this.