Creating an official github mirror

2019-01-12 16:28发布

How do I create a github mirror for an external git repository, such that it appears as "real mirror", e.g., as in https://github.com/mirrors?

So far, I set up a mirror using:

cd /path/to/bare/repository
git remote add --mirror github git@github.com:user/repo.git

and configure the post receive hook to do a git push --quiet github. This way, however, github does not recognize the mirror.

Any ideas how to do it the github way, such that "Mirrorred from" appears underneath the repostiory name?

4条回答
ゆ 、 Hurt°
2楼-- · 2019-01-12 17:04

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
查看更多
冷血范
3楼-- · 2019-01-12 17:09

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.

查看更多
SAY GOODBYE
4楼-- · 2019-01-12 17:13

The following page on github provides you with the necessary instructions to set up a mirror to an external git repo. https://help.github.com/articles/importing-an-external-git-repo

查看更多
再贱就再见
5楼-- · 2019-01-12 17:21

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

查看更多
登录 后发表回答