Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to figure out how I can use git to deploy a site.

There are 3 connections in theory:

  1. [local machine] My local machine for coding
  2. [gitolite server] Private repo hosting using Gitolite
  3. [web server] VPS hosting with a clone --bare

I git push my code from [local machine] to the [gitolite server] but how do I push my code from [gitolite] to my [web server]

I'd like to automate this so all I have to do is complete a git push.

Is the best way to setup a hook on the [gitolate server] repo to run a post-update or post-receive script? But since it's a --bare repo does that mean I need to run a git push from the [gitolite server] to the [web server]'s cloned repo since I can't run a git pull since the --bare repo doesn't have a working tree?

Sorry and thanks in advance


share|improve this question
You can pull from a bare repo just fine. All of the git trees on are bare. Why don't you just push from the local machine to both servers, rather than trying to go through one to the other? – psusi Feb 10 '12 at 16:01
up vote 1 down vote accepted

One solution is:

  1. put a post-receive hook on the gitolite server to auto-push to the web server
  2. put a post-receive hook on the web server to deploy the code (I usually use git archive for this)

Then you push to gitolite, it pushes to the web server, which then deploys your new code. Done!

Alternately, you could take the git repo on the web server out of the equation and have the gitolite post-receive hook do something like:

git archive --format=tar master | (ssh -i $KEYFILE user@webserver tar -x -C /dest/dir )

which will do the deploy straight from the gitolite hook. This assumes you can ssh into the webserver as 'user' who has a private ssh key in $KEYFILE, which may have some security ramifications since anyone who can read the gitolite hook may be able to snag those values.

share|improve this answer
Great idea. I'll have a play now :) – Wasabi Developer Feb 11 '12 at 17:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.