12

I'm wondering if there is anyway to reattach a "detached" repository in GitHub?

Order of events:

  1. Forked a private repository from an organization I belong to
  2. Parent, private repository went public
  3. I made my forked repository public as well (or get billed)
  4. Now when I was hoping to submit a pull request and merge some changes, I noticed that my fork is "detached" from the parent repository (see this explanation and confirmation as to why)

Is there any hope of "reattaching" this fork? Or do I rename my repository, fork again, and copy over code?

Any suggestions welcome.

ghukill
  • 1,036
  • 17
  • 35
  • Are there any big changes you have done on your repository compared to theirs? If not, you could potentially do a `git reset --hard upstream/master` or whatever `HEAD` they are on so that your stuff is the same as theirs and push it up to update your repo (might need to do `push -f`). Creating a new branch, rebasing your HEAD against theirs and then merging in your changes. – aug Mar 25 '16 at 18:07
  • Thanks for the suggestion, but not having luck that route. Tried `reset --hard`, which worked, but the root problem is that the repositories don't seem to be aware of one another on GitHub. Still want to submit pull requests from time to time. – ghukill Mar 25 '16 at 18:20
  • 3
    You have the git repo on your machine, right? So why don't you delete your github repo, fork again, change remote URL of repo on your machine, and finally push to your forked github repo? – saeedgnu Mar 25 '16 at 18:48
  • @saeedgnu, genius. Thank you SO much. I was over-complicating the situation, that was a perfect and elegant solution. – ghukill Mar 25 '16 at 19:27
  • The converse question (detaching) is more popular and has more answers and more info https://stackoverflow.com/questions/16052477/delete-fork-dependency-of-a-github-repository https://stackoverflow.com/questions/29326767/unfork-a-github-fork-without-deleting https://stackoverflow.com/questions/18390249/github-make-fork-an-own-project – MarcH Sep 21 '21 at 20:22

2 Answers2

10

Thanks to @saeedgnu for the elegant and perfect suggestion. Solution was to:

  1. Make sure to pull and update local git repository from personal, detached fork GitHub repository
  2. Delete personal, detached fork GitHub repo
  3. Re-fork repository on GitHub
  4. The key: the local git repository is still pointing at the correct GitHub repo. It has the current code from your now-deleted, detached GitHub fork, so you can push changes (and continue to submit pull requests) like nothing ever happened!

Phew. Crisis averted.

Cole Hudson
  • 120
  • 1
  • 1
  • 7
ghukill
  • 1,036
  • 17
  • 35
  • 3
    If deleting the old repo feels scary, you can replace bullet point 2 with "Rename your detached fork to something like MyRepo-old." The rest of the instructions work the same. – Pär Winzell Oct 09 '19 at 21:18
6

The answer to delete the repository is destructive and will lose any progress and comments in open pull requests.

The best solution is to contact GitHub via a support message detailing that you have changed a repository from private to public and the forks are in a detached state. GitHub will do the change for you, in my case within 30mins.

Support contact form: Github support contact page

Aiky30
  • 705
  • 6
  • 12