pjmorse
pjmorse

Reputation: 9294

How can I automatically keep two bare git repos in sync?

We've been using private git repositories via SSH for a while, and that's working pretty well for us. Now we want to make read-only versions available for deploying code, i.e. allow a remote user to check out code for deploying but not be able to push back to the repo.

(This is intended to let us deploy to multiple production servers without needing to set up SSH access to the git server from all those remote production servers.)

So far I've been able to clone the primary from the private section out into the web root and publish it:

$ cd /path/to/web/root/git
$ git clone --bare /repos/git/project-name project-name.git
$ cd project-name.git
$ touch git-daemon-export-ok
$ git --bare update-server-info
$ mv hooks/post-update.sample hooks/post-update

...but now the resulting repo in /path/to/web/root/git/project-name.git is doomed to drift into irrelevancy unless it gets updated from the primary, and I'm not going to run git fetch manually every day. How do I automatically update it? Should I run git fetch via cron scripts regularly, or is this where post-commit hooks come in?

Upvotes: 1

Views: 1120

Answers (1)

Karl Bielefeldt
Karl Bielefeldt

Reputation: 49118

That's what hooks are for, but if they're both on the same machine, I would personally just use a symbolic link.

Upvotes: 2

Related Questions