4

There are 3 repos:

  1. There is OpenAI Baselines repo: https://github.com/openai/baselines.
  2. I have its fork: https://github.com/sytelus/baselines.
  3. Another user has its fork: https://github.com/hill-a/stable-baselines.

Now I want to fork #3, i.e. https://github.com/hill-a/stable-baselines. However, GitHub isn't allowing it by saying "You've already forked stable-baselines". I actually don't have fork of stable-baselines but only its parent. So message is wrong. In any case, this doesn't make sense to me at all. The #3 has now diverged immensely and has many different features. I want to send pull request to both. However, without having both forks I can't do it.

Any solution?

Shital Shah
  • 63,284
  • 17
  • 238
  • 185

2 Answers2

2

It is not, indeed, possible to fork a fork.

If the #3 repository has diverged, it would make sense for the owner of #3 to create a separate (non-fork) repository with its content, that you would then fork, in order to enable PR.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    What if owner still wants ability to send pull requests for *parts of project* that isn't diverged yet? This restriction doesn't make sense at all. – Shital Shah Nov 01 '19 at 07:26
  • @ShitalShah then the owner send PR from their fork, but also make the same commits in the separate repository if needed. – VonC Nov 01 '19 at 07:27
2

While @VonC has provided the fact that it's not possible to have two different fork of the forks, I want to add two things to this answer:

First, this seems to be an unfortunate design decision by GitHub and there is no technical reason for not allowing this. Every repo should be able to point to whatever upstream it wants to enable PR mechanism to work. For a platform that intends to promote collaborative development, this is quite a mind-boggling limitation.

Second, I want to provide a way so you can still do this but with extra work from your part. Let's say there is repo R and their two forks R1 and R2 by some users. You want to be able to work on R, R1 and R2 and send them your pull requests. Here's how you can accomplish this:

  1. Clone R locally and then create new github repo from it. This would mean that your repo would not appear as fork and you can't send PRs from it to R.
  2. Add remotes for each fork using git remote add r1_fork https://github.com/<user1>/R1.git.
  3. For each fork create its own branch using git checkout -b r1_fork.
  4. In each branch, fetch the changes from that fork: git fetch r1_fork.
  5. After fetch do hard reset in that branch for that remote: git reset --hard r1_fork/master.

Now you can work in branch for each individual remote and make changes. However, you can't send PRs yet. For sending PRs, you will need to fork that repo, then merge changes from your branch to the fork, send PR and delete the fork. Obviously, this is very non-ideal but this is what we got until GitHub fixes their stuff.

Shital Shah
  • 63,284
  • 17
  • 238
  • 185
  • " there is no technical reason for not allowing this"... actually, there is a ton of technical reason, when you consider the *scale* at which GitHub operates. (like in https://github.blog/2017-10-13-stretching-spokes/) – VonC Nov 14 '19 at 11:46
  • 1
    Could you please elaborate? Tons of problem can be solved at scale. What problem allowing this feature poses that can't be solved at scale? – Shital Shah Nov 15 '19 at 10:11
  • That would be a good question for the engineering team (https://github.blog/category/engineering/). The point is: what seems a simple feature from outside GitHub might end up extraordinarily complex for the poor soul who has to implement it. It seems trivial (https://blog.codinghorror.com/code-its-trivial/), but it is probably not (http://steve-yegge.blogspot.com/2009/04/have-you-ever-legalized-marijuana.html) (one example amongst many: how do you manage a fork queue: https://github.blog/2008-12-16-the-fork-queue/, when forks have forks?) – VonC Nov 15 '19 at 11:53