在不删除的情况下取消 GitHub 分支

我想“ unfork”一个 GitHub 分支而不删除 + 重新创建它。这可能吗?

我的理由是,我的项目现在对 fork 的源代码有了完全不同的用途,显示提前提交的次数或者 pull request 按钮(或者至少有这样的突出显示)是没有意义的。事后看来,我觉得我应该只用 git cloned 原件,而不是叉子。

我想不删除我的叉子,以保持问题 + 拉请求的历史。

我很乐意保留提交的历史记录,它只是删除了我想要的 fork 状态。

59194 次浏览

I remember reading about this almost a year ago in one of GitHub's help pages. They mentioned to contact the GitHub staff explaining your situation. The staff will do the needful.


EDIT

After browsing through the GitHub pages list, I see that I was a bit off about the actual task. The page I remembered was Transferring a repository; in particular:

If the transferred repository has any forks, then those forks are associated with the new repository after the transfer is complete. Keep in mind that users who have forked your repository will need to update their remote URLs to point to the new Git repository in order to continue opening pull requests.


It is still worth it to contact the staff with your particular issue and ask them to separate your fork from the network.

This method will create a new "unforked" repository while maintaining everything else in the Git repo (commit history, branches and tags). It does not migrate GitHub specific metadata (issues, pull requests, wikis, releases, etc).

How to "unfork" a project in four easy steps:

  1. git clone --bare https://github.com/{username}/{repository}
  2. Delete original repository in https://github.com/{username}/{repository}/settings.
  3. Create new repository with the name {repository} at https://github.com/new.
  4. cd {repository}.git and git push --mirror https://github.com/{username}/{repository}

And done!

Note: The following does not migrate GitHub specific metadata (issues, pull requests, wikis, releases, etc).

Na, na. GitHub is far more powerful than you think.

Undoubtedly, there's no way but make a bare copy of all of the codes. However, the copy procedure can be done by GitHub itself. So, no pain of mirroring the code with our own bandwidth.

Step by step:

  • Click the "+" on top right corner, select "Import repository"
  • Paste the old repo url (like https://github.com/user/repo) and enter a new name.
  • Click "Begin import"

Done. GitHub will even give you an email notification when copy'n'paste is done.

Tested to work against my own project. Good feature isn't it?

I found the following in the official github documentation:

To detach the fork and turn it into a standalone repository on GitHub, contact GitHub Support. If the fork has forks of its own, let support know if the forks should move with your repository into a new network or remain in the current network. For more information, see "About forks."

from https://help.github.com/articles/why-are-my-contributions-not-showing-up-on-my-profile/#commit-was-made-in-a-fork

Unfork without deleting the repository

  1. Go to this link https://support.github.com/request?q=unfork
  2. Click on "Our virtual assistant can help with detaching/unforking a repository"
  3. Click Detach
  4. It will ask for the Repository link