Using Git to deploy code changes..

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.

Add new comment

Filtered HTML

  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.