local cache for a github repository?

Your latest comment makes it clear you're looking for a performance optimization. That helps.

You can start by creating a local mirror of the github repository following these instructions. You can either periodically update it, or arrange to receive web hooks from github to update the local mirror "on demand". To do this you would need to set up a small web service that would respond to the hooks from github. You can add a web hook by going to https://github.com/someuser/someproject/settings/hooks/new. You will probably want to select the "Let me select individual events" radio button, and then select:

  • delete
  • push
  • create

This would keep your cache up-to-date with respect to changes in available tags and branches.

Set up a git server that makes that repository available locally. This can be as simple as running git daemon, or a local account accessible via ssh, or something more full featured, depending on your local requirements.

Then you would set up your local working copies like this:

$ git clone http://localrepository/someproject.git
$ cd someproject
$ git remote set-url --push http://github.com/someuser/someproject.git

This would set up each repository to pull from your local cache, but push changes upstream to github.


You should check out the git-cache-http-server project. I think it partly implements what you need (and is similar to the idea from @larsks post).

It is a NodeJS piece of software that runs an HTTP server to provide you access to locally cached git repositories. The server automatically does fetch upstream changes when required. If you use those local git repositories instead of the distant ones, your git client will be served locally cached content.

If you run the git-cache-http-server on a separate host (VM or container for example), you can configure your local git client to automatically clone and fetch from the cache by configuring it to replace https://github.com with something like http://gitcache/github.com. This can be achieved by a configuration like:

git config --global url."http://gitcache:1234/".insteadOf https://

At the moment, this software only provides a cache to clone and update a repository, there is no provision for pushing changes back. For some use cases, thinking about a CI infrastructure that needs to pull content of multiple repositories even when only a single one has changed or the automated testing you mention, this can be useful.


Look at git clone --reference-if-able to take objects from another (in your case on-site) repository.