4

I have a question about git repository replication across several live http servers

My goal was to create replication from my test server to the live http servers. So when I'd commit my changes on test, the changes should automatically appear also on server I had a look at gerrit2 and it looks ok but I tried to do it with git, but since git uses post-commit hook I’m sure I’d be able to do it with that

So I tried doing multiple pushes in the hook after commit ( since overwriting seems to be only option because if I merged there’d a chance of conflicts and last thing I want to have on my live server are messed up files...) from test to live and firstly I got some odd errors, but then I added the force parameter and push succeeded but unfortunately the changes did not appear on remote server. I was using ssh protocol to exchange data.

How to do it so it will be good and reliable? What is the set of commands I must execute?

1
  • Pushing to a checked out branch in a non-bare repository is generally bad; it updates the index but not the working tree. Git should have warned you fairly strongly about this when you did those pushes. If you really want to do it, you need to run git reset --hard on the other end afterwards.
    – Cascabel
    Commented Sep 30, 2011 at 2:30

2 Answers 2

1

As @Jefromi points out, it is not a good idea to push.

Instead, you can try to pull from the production server, by using a script that runs at regular interval (like each hour or each multiple of 5min). That way you will know when the servers will be updated.

But if you do any modifications on the server, the pull may fail because it will refuse to update a modified file. You can make the script to check if the working copy is dirty before doing the pull and send an e-mail to have someone to look at the server.

0

Alternatively you could setup a bare repo (git init --bare) and use a post receive hook to check it out and copy it into the published directory (hooks/post-receive)

GIT_REPO=$HOME/blah
TMP_GIT_CLONE=$HOME/tmp/tmpblah
PUBLIC_WWW=/srv/public_folder/

git clone $GIT_REPO $TMP_GIT_CLONE
mv $TMP_GIT_CLONE $PUBLIC_WWW
exit

This is how i manage the sites on my server i push to both my code repo (gitosis setup) and to a repo that checks out and deploys the changes to production

A simple feature improvement would be to add an incrementing value into your deploy script and deploy into a new folder each time and simply update a symlink to point to it

so a push today would go to 2011102900 the next to etc and a symlink would link current to whichever folder is newest (and be updated by the post_receive script)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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