96

I forked a project, made some changes, and got a pull request accepted. But now, the project I forked moved to another repository and is a fork of that repository.

That is:

Original -> MyFork

Now:

NewOriginal -> Original -> MyFork

How would I get it to the following?

NewOriginal -> MyFork
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
LanguagesNamedAfterCofee
  • 5,782
  • 7
  • 45
  • 72
  • 48
    The accepted answer provides a workaround, but doesn't really answer the main question, how to change the "forked from" metadata on GitHub itself. I am interested in the same thing. – Matthew Flaschen Dec 25 '12 at 22:57
  • 2
    @MatthewFlaschen Me too. Perhaps the easiest way is to just re-fork it in GitHub's UI and then push your local fork repo to the new fork? Would be great just to adjust this in GitHub's UI, though. – Joshua Pinter Feb 02 '21 at 17:48
  • Why does this question just sit here, not really answered? Is there no suggestion/issue to resolve in Github someone can point to? What an obvious piece of missing functionality this is, embarrassing for Github IMHO. – mhd Mar 18 '22 at 19:07

5 Answers5

82

NOTE: The following solution is incomplete as you'll lose all wiki content and issues specific to your fork.

You can achieve this using the following steps:

  1. Pull down all branches and tags from your existing fork.
  2. Delete your repository on GitHub.
  3. Fork from the new repository.
  4. Update the remote URL if necessary.
  5. Push all your local branches and tags to the new repository.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Castrohenge
  • 8,525
  • 5
  • 39
  • 66
  • 9
    This is the correct answer to the question asked -- the OP needs to change github's view of the "parent", so when he issues pull requests, they go to the new parent and not the old one. It does seem like the only answer is to delete the repository and fork again. – Ether Aug 25 '13 at 17:38
  • 48
    This is a workaround for a missing feature in github. – abergmeier Jan 15 '14 at 10:25
  • 4
    Such a shame github still doesn't have a nicer workflow for this. – Ashimema Sep 08 '15 at 21:26
  • 2
    May be worth adding that there are scripts put there to allow you to migrate issues from github repository to repository, and that as github wikis are themselves just git reps you could migrate that too – Ashimema Sep 08 '15 at 21:36
  • 1
    Thanks! But can you show the git commands for how to actually do these steps? Ideally including forking and restoring the github wikis also? And @Ashimema, can you link to good scripts for migrating issues? – nealmcb Aug 28 '19 at 15:14
  • 2
    It is worth noting that if you had open PRs in the correct fork parent repo. Deleting, re-forking and pushing will not update the branches in the open PRs. Those branches are now orphaned. – gnikit Mar 04 '21 at 20:28
58

Locally you can just change the target of the original repository is located at. Usually that repository is called upstream, so you would do this:

git remote set-url upstream git://example.com/NewOriginal.git

Depending on what host you are using (that is, where your fork is located), there might be some additional internal links, you can't change so easily. For example on Github, the fork is directly linked to the original you forked from. In that case you need to fork the new project again, and work with the new fork.

In that case however you can easily change the URL of the origin repository as well, and just push everything you changed before in your old fork into your new fork.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
poke
  • 369,085
  • 72
  • 557
  • 602
  • 12
    usually the remote for the upstream repository is called `origin` – knittl Apr 21 '11 at 20:16
  • 9
    @knittl: Not really, the upstream repository is the original repository the fork is based on. Origin is your public repository you cloned from, i.e. the fork. – poke Apr 21 '11 at 20:17
  • 2
    what‽ if you clone a repository the branches of that repository will be available through the `origin` remote. the url of the `origin` remote is the url which was cloned from. there is no `upstream` remote by default in git – knittl Apr 21 '11 at 20:20
  • 5
    @knittl: Never said that it was there by default, but *usually* you add the *original* project as well as a new remote called *upstream*, so you can actually update your fork from the original project... – poke Apr 21 '11 at 20:22
  • well, you could simply leave the origin url to point to the origin repository – which, since it is a clone of the other repository – will contain the "NewOriginal" repository – knittl Apr 21 '11 at 20:24
  • 6
    This is correct for git, but not for GitHub. [This answer](http://stackoverflow.com/a/17366793/2063546) is the correct one for GitHub. – Ian Aug 28 '14 at 16:06
10

Update the remote URL in your repository:

git remote set-url origin <url to NewOriginal, e.g. git://…/bla.git>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
knittl
  • 246,190
  • 53
  • 318
  • 364
  • 4
    That won't work. The OP still needs origin set to MyFork so that he can do pull requests against NewOriginal once he's pushed his changes to MyFork on GitHub. He doesn't have write access to NewOriginal so setting origin to that will cause his pushes to fail. – Guy Sep 24 '14 at 17:50
7

It appears that Github refers to this as "rerouting" a fork. This can be requested as a manual human action, as a support request.

jkmartin
  • 153
  • 1
  • 7
  • Note: I am not confident this is correct, as documentation is silent on what exactly they mean by 'reroute'. However, it's grouped with "attach"/"detach" a fork [here](https://support.github.com/request/fork), so that's *very probably* what it means. – jkmartin May 12 '22 at 19:35
  • I can now confirm that a reroute request was fulfilled as a change of 'forked from' metadata. – jkmartin May 19 '22 at 19:32
0

Assuming you performed the proper forking and adding upstream see githubHelpOnFork ; to just change the upstream URL, do:

  1. verify what your current upstream and origin looks like :

    git remote -v
    
  2. if you see upstream listed and you want just change its url, do what @poke suggested (if not follow the helpGithub link above to add a new upstream) :

    git remote set-url upstream git://example.com/NewOriginal.git
    
  3. then verify that upstream is pointing to the new URL

    git remote -v
    
fuesika
  • 3,280
  • 6
  • 26
  • 34