Mick
Mick

Reputation: 31919

Delete fork dependency of a GitHub repository

How can I make GitHub forget or disassociate that my repo was originally a fork of another project?

I forked a project in GitHub. I can now see "forked from whatever/whatever". The parent repository "whatever/whatever" is no longer maintained. I have been allowed to continue use of the code base of the original repository to create an independent repository.

Is there a way to detach my project from the original repository?

Upvotes: 357

Views: 126308

Answers (9)

The Matt
The Matt

Reputation: 1724

GitHub has added a Help Page with steps to do just this, to detach a fork.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/detaching-a-fork

A summary of the steps goes as follows:

Please Note

Deleting a fork will permanently delete any associated pull requests and configurations. This action cannot be undone.

  1. Record any information you want from the current repo that won't otherwise be preserved, such as the repo description.
  2. Clone the repo, can just be a --bare clone.
git clone --bare https://github.com/EXAMPLE-USER/FORK-NAME.git
  1. Delete the repository on GitHub.
  2. Create a new repository under the same GitHub account with the same name.
  3. Push your local repo to the GitHub repo with the --mirror flag.
cd FORK-NAME.git
git push --mirror https://github.com/EXAMPLE-USER/FORK-NAME.git

Upvotes: 2

GOTO 0
GOTO 0

Reputation: 47682

Log in to GitHub with your credentials.

Go to https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork

Choose "Detach", then enter the URL or repo name of the fork as your-user-name/repository-name, and answer the other questions of the virtual assistant.

You will get an email with a ticket number where you can check the status of your request. You will also be notified per email once your repo has been deforked.

Most repository settings will stay unchanged, including user permissions, stargazers, issues, PRs, discussions, etc.

Upvotes: 37

Antonio O.
Antonio O.

Reputation: 555

This only applies to GitHub Enterprise, not on github.com

This approach will preserve all the branches, pull requests, and everything else, but it requires the user to be logged in to an account that has admin privileges.

  1. Log in with admin privileges
  2. Go to the repository that you need to detach: https://<ghe url>/<org>/<repo>
  3. Click on the “Site Admin” rocket on the top right corner
  4. Click "Collaboration" on the top menu bar
  5. Click on “Network” on the left pane
  6. Click on “Detach” in the Network Structure pane
  7. Accept

This was tested on GitHub Enterprise 3.3

Upvotes: 18

Thomas Moulard
Thomas Moulard

Reputation: 5542

Update Jan 2022:

Use the GitHub chatbot-virtual-assistant at https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork

First answer: You can contact github support and ask them to switch your repository to "normal mode".

On this page, "Commit was made in a fork" paragraph, it is explained that one has to go through support to switch. Therefore, it is likely that there is no way to do that by yourself (unless you destroy and recreate your repo which is explained before... if you do so be careful if you have tickets or a wiki attached to your project as they will be deleted!).

Upvotes: 345

Narcis
Narcis

Reputation: 173

If you do not need any past commits (I didn't in my case), you can just:

  • fork the project
  • make a local copy of the fork (I used my IDE to do that)
  • delete the git folder from your local copy
  • commit the project as you normally would a new project.

You can just delete the fork from your github account after. Took me all of one minute and worked like a charm.

Upvotes: -1

Juuso Ohtonen
Juuso Ohtonen

Reputation: 9662

You could duplicate the forked repository to a new repository (without the fork dependency) from the GitHub UI, then remove the original forked one:

  • Sign in to GitHub
  • Select the + sign in the top right corner and select Import repository.
  • Import your forked repository. The new repository won't have the fork dependency.
  • Delete the original, forked repository in the repository settings.

NOTE: This approach will not preserve issues and pull requests.

Upvotes: 134

Grokify
Grokify

Reputation: 16334

Using the info from aurelien and Clayton, I was able to do this with the following:

$ git clone --bare https://github.com/my/forked_repo.git
<delete forked_repo on GitHub>
<recreate repo on GitHub using same name>
$ cd forked_repo.git
$ git push --mirror

Here's the documentation for git clone --bare:

Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.

Here's the documentation for git push --mirror:

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.

Note: like the other git based answers, this will not copy over issues that are not part of the git repo such as the wiki and issues. Per Tapio:

  • The wiki is a separate git repo and can be handled in a similar fashion per Tapio. The address is: [email protected]:user/repo.wiki.git.
  • Issues can be exported via the GitHub API but there are issues recreating them since they can only be created by your user, so imports will lose information.

Upvotes: 21

aurelien
aurelien

Reputation: 868

I got the similar problem, and ended up using this github help page to solve it. I didn't mind about the wiki and issues tracker as it was for my blog using a theme kindly developed by another user.

To detach a forked repo and use it as your own after several commits without losing the whole history:

git clone --bare [email protected]:user/forked_repo.git

Create a new empty reposity new-repository on the github website. And push a mirrored version:

cd user.github.com.git/

git push --mirror [email protected]:user/new-repository.git

One can rename on github, the forked_repository with another name to keep it as backup and check updates if needed. Or simply delete it.

Renaming the new-repository to the original name does the job. As a side effect, your commits now appear in your history.

Upvotes: 29

Tapio
Tapio

Reputation: 3456

Make sure you have all the important branches and tags on your local repo, delete the github repo, recreate the repository through usual means (no forking) and push the local repository back with git push --all. Note that if you have local branches that you don't want to publish, might be worth to create a temporary clean local clone for the operation.

However, this will also get rid of wiki and issues. As the wiki is in fact it's own repository, it can be handled similarly by cloning it and then recreating and pushing. The repo address is on wiki's Git Access page ([email protected]:user/repo.wiki.git).

This leaves issues. They can be exported through the API, but as far as I know, you can only create issues and comments with your person, so importing them perfectly is impossible.

So, if you need issues to be preserved, you should go through github support as Thomas Moulard suggests.

Upvotes: 46

Related Questions