Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an official github mirror

People also ask

How do I create a mirror in GitHub?

If you want to mirror a repository in another location, including getting updates from the original, you can clone a mirror and periodically push the changes. Open TerminalTerminalGit Bash. Create a bare mirrored clone of the repository. Set the push location to your mirror.

What does mirror mean in GitHub?

Repository Mirroring is a way to mirror repositories from external sources. It can be used to mirror all branches, tags, and commits that you have in your repository.


Based on communicating with GitHub's support team, I found that GitHub currently offers no direct mechanism for a user to mirror repositories in this fashion.

However, one can ask GitHub to install this service for repositories which are part of an organization. GitHub then configures an existing repository as such a mirror and pulls from it in an interval that is a function of the number of overall mirrors they have.

EDIT: as Stuart points out, GitHub no longer accepts requests for mirroring arbitrary repositories. The only remaining option is the solution I posted in my question, i.e., creating a post-receive hook to automatically push to your GitHub repository.


Judging by the current content of https://github.com/mirrors, it would appear GitHub no longer does "official mirrors", as most projects that want their code mirrored on GitHub today just makea an organization for it, such as Git itself.

There is also a feature request at: https://github.com/isaacs/github/issues/415


According to Importing a Git:

For purposes of demonstration, we'll use:

  • An external account named extuser
  • A GitHub personal user account named ghuser
  • A GitHub repository named repo.git

The command line:

# Makes a bare clone of the external repository in a local directory  
$ git clone --bare https://githost.org/extuser/repo.git

# Pushes the mirror to the new GitHub repository
$ cd *repo.git*
$ git push --mirror https://github.com/ghuser/repo.git

# Remove the temporary local repository.
$ cd ..
$ rm -rf repo.git

I have used a tool called github-backup with moderate success to, if not mirror, at least make a full backup (including issues and other metadata) of a Github user or organization. To quote the README file:

Each time you run github-backup, it will find any new forks on GitHub. It will add remotes to your repository for the forks, using names like github_torvalds_subsurface. It will fetch from every fork.

It downloads metadata from each fork. This is stored into a branch named "github". Each fork gets a directory in there, like torvalds_subsurface. Inside the directory there will be some files, like torvalds_subsurface/watchers. There may be further directories, like for comments: torvalds_subsurface/comments/1.

You can follow the commits to the github branch to see what information changed on GitHub over time.

The format of the files in the github branch is currently Haskell serialized data types. This is plain text, and readable, if you squint.

Limitations include:

  • no private repository support
  • no "social" stuff like stars, followers, etc
  • notes to lines of commits are not supported (yet?)
  • issue labels