125

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?

mavam
  • 12,242
  • 10
  • 53
  • 87

5 Answers5

128

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.

Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
mavam
  • 12,242
  • 10
  • 53
  • 87
  • I have a newbie question: what's the use of mirroring a repo, and thus creating two copies of the same repo? Wouldn't this cause confusion? I mean, if I were to create an PR, which site should I use? Is this for gaining exposure so people can find the repo on Github? – Tom Charles Zhang Jun 01 '23 at 13:46
  • @TomCharlesZhang some people have their repos in their own servers/websites, for instance, the linux kernel is hosted on kernel.org, but since github is so popular, its useful to have a mirror there so people that are not too familiar with other webpages can find your projects easily. – Fabián Montero Aug 09 '23 at 20:26
13

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

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Stuart P. Bentley
  • 10,195
  • 10
  • 55
  • 84
7

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
eQ19
  • 9,880
  • 3
  • 65
  • 77
  • 5
    What's the difference between `git clone --bare` and `git clone --mirror`? Isn't the second variant more fitting here? – user7610 Mar 02 '17 at 20:10
1

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
anarcat
  • 5,605
  • 4
  • 32
  • 38
1

One could set up a cron action on the repo to achieve both push- and pull-style mirroring.

silverwind
  • 3,296
  • 29
  • 31