HACKER Q&A
📣 lloydatkinson

Good way to mirror many GitHub repos with a self-hosted Gitea?


I've always been worried about putting all my eggs in one basket and while I'm very happy with GitHub I'd like to be able to mirror all my repositories to something self-hosted (like Gitea) in case of any extended GitHub downtime. Bonus points if it can also mirror anything I've starred too.

Is there a pre-built solution to this, or am I going to have to write a script/program that clones from GitHub into Gitea with cron?


  👤 boricj Accepted Answer ✓
In a previous sysadmin job, I've had to deal with major network performance bottlenecks between our CI lab and the company's uplink, where all our git clones/pulls went through. I had to improvise a solution, so I wrote a Git proxy/cache in bash.

You set up that script as a login shell for a SSH account. Each client is configured with git-config's url..insteadOf to rewrite Git URLs to go through this SSH endpoint. The script then either clones or pulls from the remote and then serves the client by exec()'ing git-upload-pack from the local copy.

One side effect is that this Git proxy/cache accumulates a complete local copy of everything that was ever cloned or pulled through it. Configure your development system to use it and you have yourself a remote server with an on-disk mirror that tracks everything you've cloned or pulled.

I haven't used this personally in years, but it's still in production as far as I know at my previous job. You can find that script here: https://gist.github.com/boricj/909d3df166af8c5c2fe9fa66bdce8...