Creating a Read-only Mirror for Your GitHub Server
Recently we’ve been transitioning our git repositories to GitHub. We chose to go this route for a variety of reasons, but mostly because they have kickass pull requests, which we’re going to test run as code reviews. However, one of the requirements of this process was that our original git-server still remain functional, in at least a read-only state. This saves us the time of having to update deploy and other scripts which read from this mirror and perform various tasks.
I was a bit surprised when I originally searched around for this, as I was either failing horribly at Google (granted, my queries were “how to setup git-server mirror”), or there just wasn’t much information out there on it. After a bit of crawling I found what seems to be a pretty easy way to get the behavior we wanted. For a recap, here’s a checklist of what we needed:
- Read-only git server
- One-way mirror from our new server to the legacy server.
- Mirror all branches
- Updated near real-time
So, given this, we created a simple bash script that runs on a 1 minute cron timer (it’s as close to real-time as we needed):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Since we were already using gitosis for permissions, it was easy for us to deprecate the legacy repo by simply moving everyone into a readable group that lacks write privileges.
Would love to hear some feedback from avid git users if there’s a better way to do this.