1

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

WD

1
  • You can pull from a bare repo just fine. All of the git trees on kernel.org 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? Commented Feb 10, 2012 at 16:01

1 Answer 1

1

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.

1
  • Great idea. I'll have a play now :) Commented Feb 11, 2012 at 17:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.