101

I would like to "unfork" a GitHub fork without deleting + recreating it. Is this possible?

My reason is that my project now has a completely different use to the source of the fork, and makes no sense to be showing number of commits ahead, or the pull request button (or at least, with such prominence). With hindsight, I think I would have just git cloned the original, rather than made a fork.

I would like to not delete my fork in order to keep the issues + history of pull requests made.

I am happy to keep the history of commits, it's just the removal of the fork status that I'm after.

friederbluemle
  • 33,549
  • 14
  • 108
  • 109
Michal Charemza
  • 25,940
  • 14
  • 98
  • 165
  • I'd be interested to know what the solution is for a general git repository, rather than specifically for GitHub. – Arj Dec 13 '16 at 17:04
  • 1
    @Arj I was under the impression that a fork is a GitHub-specific concept, so I suspect there is no solution, because there is no problem! – Michal Charemza Dec 14 '16 at 08:54
  • I didn't realise it was GitHub specific, thanks! However I am using Atlassian Stash which also allows forks, hence why I must have assumed its generic. I may dig around on their forums. – Arj Dec 21 '16 at 16:05
  • 3
    Possible duplicate of [GitHub: make fork an "own project"](https://stackoverflow.com/questions/18390249/github-make-fork-an-own-project) – 0 _ Oct 20 '17 at 13:06
  • and also [Delete fork dependency of a GitHub repository](https://stackoverflow.com/questions/16052477/delete-fork-dependency-of-a-github-repository) – MarcH Sep 21 '21 at 20:20

5 Answers5

77

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

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.


Updates on Jan, 2023.

Github support now provide "unfork" operation upon request. Just open a support ticket at https://support.github.com/contact?tags=rr-forks

ttimasdf
  • 1,367
  • 1
  • 12
  • 19
  • 3
    Will this bring issues across, too? – chris Jul 04 '17 at 04:27
  • 1
    @ChrisAnderson I didn't try it but I guess not. For it accepts any valid git url, I guess it does nearly `git clone --bare` kind of stuff. – ttimasdf Jul 26 '17 at 08:50
  • 2
    +1 This should be the accepted answer. So you only need to rename your forked repository, and import to a new repository with the original name. – sean Sep 28 '17 at 07:06
  • This shouldn't be the accepted answer. You loose the issues, wikis, etc. – Zardoz89 Jul 04 '21 at 07:12
  • This also does not seem to work if you want to unfork a repo forked from a private repo of a different user. Keeps asking me for credentials of the repo (which I correctly provide). – tnagel Sep 08 '21 at 15:35
60

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!

friederbluemle
  • 33,549
  • 14
  • 108
  • 109
Tiago A.
  • 2,568
  • 1
  • 22
  • 27
  • There should be also point "2.5. Create new repository with old name." - otherwise push tells `remote: Repository not found.` – BartBiczBoży May 12 '17 at 06:44
  • 8
    Luckily OP mentioned "I would like to not delete my fork in order to keep the issues + history of pull requests made." – Arcesilas Nov 13 '17 at 02:00
  • 2
    It does not maintain pull request. Is there a way to maintain pull requests durning un-forking? – user1858796 Jan 23 '20 at 09:57
  • You would also need to recreate any secrets https://github.com/{username}/{repository}/settings/secrets – rectalogic Apr 27 '20 at 20:40
  • What if original repository is not in my control and I cannot delete original repository? – Shiv Dec 28 '22 at 06:29
28

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.

Web_Designer
  • 72,308
  • 93
  • 206
  • 262
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • 10
    I contacted the staff at https://github.com/contact, explained my situation, and they have now unforked it. Or to use their term, "extracted into its own fork network". Thanks! – Michal Charemza Mar 29 '15 at 09:55
  • 9
    Some updated info: if you visit https://support.github.com/contact?tags=rr-forksm and type as subject "detach fork from parent repo", the option is given of getting help from GitHub's Virtual Assistant via web-based chat. It asks for the repo URL, you give it, and voila! It's done. – phlummox Jan 25 '21 at 15:25
27

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

dpoetzsch
  • 757
  • 1
  • 7
  • 19
  • This should be the accepted answer. As of Sept 2022 there is no other official (user accessible) way to detach a fork while maintaining all GitHub metadata. – friederbluemle Sep 23 '22 at 02:44
10

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
Vitim.us
  • 20,746
  • 15
  • 92
  • 109