1

Say there is a repo (L), for example, llvm. There are thousands of forks on it. Let's say someone forked from the repo L at commit Cx; let's call the forked repo F1. Over a period of time, features were added to F1 and it is still growing and let's say it is at rev Rx.

Similarly someone else forked the repo L at commit Cy; let us call the forked repo F2. Again this forked repo also grew in time and still growing and let's say it is at rev Ry

Now my question is I would like to have all the changes of Forked Repo F1 till R1 and all the changes of repo F2 till R1 in my own fork from the same parent L.

enter image description here

Just to be more clear with my expectations. Gray box is the Parent repo L. Blue box is a Fork F1 with different commits A1, B1... I1. Similarly Red box is Fork F2 with different commits A2, B2 ..F2.

Now the Green box is Fork which I'm expecting with the changes of fork F1 and F2. It doesn't matter to me where I create the fork from Parent. As long as I get all the changes available in F1 and F2 I'm okay with the expected fork of mine.

Is it possible to do such things in github? I did try to cherry pick. But there are way too many commits in F1 or in F2. I'm not sure what is the best and easiest way to do a cherry-picking. Or should I merge the fork F1 with F2 or F2 with F1? Not sure how to do that either.

Thanks in advance for your help and support.

Olsonist
  • 2,051
  • 1
  • 20
  • 35
SantMan
  • 77
  • 6

1 Answers1

1

If i understand you correctly, you can do this with a simple merge/rebase once you know the forks (and branches) you're interested in. Git will take care of handling the differences between you and your forks. You could say this is a "reverse pull-request".

Let's say I have three repositories. One base and two forks. Base progressed a bit after the forks were made. I'll need to know which forks i'm interested in, ofcourse.

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git remote add fork1 ../fork_test_1

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git remote add fork2 ../fork_test_2

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git remote -v
fork1   ../fork_test_1 (fetch)
fork1   ../fork_test_1 (push)
fork2   ../fork_test_2 (fetch)
fork2   ../fork_test_2 (push)

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git fetch fork1
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From ../fork_test_1
 * [new branch]      master     -> fork1/master
(same for fork2)

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git ls master..fork1/master
ac45d82 (fork1/master) change 2 from fork 1 [Martin Kjeldsen]
ee9d670 change 1 from fork 1 [Martin Kjeldsen]

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git ls master..fork2/master
f00ba61 (fork2/master) change 2 from fork 2 [Martin Kjeldsen]
2936886 change 1 from fork 2 [Martin Kjeldsen]

Now i'll just merge the branches from the forks i'm interested in and resolve conflicts.

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git merge fork1/master
Auto-merging test
CONFLICT (content): Merge conflict in test
(same for fork2)

Now i have the changes from both.

zrrbite@ZRRBITE MINGW64 /d/dev/git/fork_test (master)
$ git ls -10
06c4ded (HEAD -> master) merged changes from fork 2 [Martin Kjeldsen]
6da96f1 merged changes from fork [Martin Kjeldsen]
f00ba61 (fork2/master) change 2 from fork 2 [Martin Kjeldsen]
2936886 change 1 from fork 2 [Martin Kjeldsen]
ac45d82 (fork1/master) change 2 from fork 1 [Martin Kjeldsen]
ee9d670 change 1 from fork 1 [Martin Kjeldsen]
cb8c9d3 change 2 from base repo [Martin Kjeldsen]
44074f6 change 1 from base repo [Martin Kjeldsen]
8c5151e added test [Martin Kjeldsen]
zrrbite
  • 1,180
  • 10
  • 22
  • Thanks for the response. I have trouble following some instructions. Need some more inputs. Here is the commands I forked from LLVM project. And I did a clone of the llvm fork which I created. After that I am running the following commands as suggested. git remote add apple/llvm-project https://github.com/apple/llvm-project.git git remote add espressif/llvm-project https://github.com/espressif/llvm-project.git git fetch apple/llvm-project git fetch espressif/llvm-project git merge apple/llvm-project merge: apple/llvm-project - not something we can merge – SantMan Sep 14 '20 at 21:11
  • 1
    "not something we can merge" usually arises from typos or missing branches/references. Looks like you only specified the remote, and not which branch to merge: `git merge apple/llvm-project`. So, you also need to find out which branch from the fork you're interested in. This is usually handled via "pull requests" in github, for instance. E.g. `fork1/mybranch -> origin/master`. Here you're on your own guessing what the pull request should be :) – zrrbite Sep 14 '20 at 21:17
  • Thanks for the quick response. Apologies for the indent stuff in my previous comment. Yes you are correct with the branch name. Now I have lot of merge conflicts which I need to resolve before I proceed. I will post a message once I finish resolving those conflicts hopefully in next couple of days :) – SantMan Sep 14 '20 at 21:23
  • 1
    Yes. In the actual command I typed it was there. It is not showing up here in these comments for some reason. – SantMan Sep 14 '20 at 21:25
  • Just a quick followup question. Once I resolve all the conflicts how to specify to which of the fork or repo i need to push the changes? just normal `git push origin master` will push it to the repo I cloned from llvm? or is there any remote i need to reset? – SantMan Sep 14 '20 at 21:36
  • 1
    If you used "git clone ", then origin will be . And if master is the branch you want to update, then yes `git push origin master`. If you've merged, then you can push as usual, if you're using rebase you'll need to `git push --force-with-lease`. Use `git remote -v` to see which references you've configured. – zrrbite Sep 14 '20 at 21:40
  • there are around 3000 files which has merge conflicts. I'm resolving them one by one. Fixed around 500 files so far. It is a slow process rather :( – SantMan Sep 20 '20 at 07:28