How merge 2 github repository to trigger a pullrequest?

85 views Asked by At

I'm sure there are ton of documentation, but nothing appear clear to me.

I want to contribute to opensource projet, do a real PR for the first time. (Late is Better than Never).

To start easy, I just want to take the work someone did on a github fork (but didn't push back to the master), do some small update and then try to make a PR to the original repository

The Master Repo is (R1):

The Forked and Updated Repo is (R2): (Attention : in a specific Branch)

I forked the ageneau repo on my account

My intent is :

  1. To do a Fork of R2 the on my github account = I did't succeed. It always fork me the R1 without the interesting branch. What to do ? I fact I already add the R1 Fork. So I deleted the R1 fork and the succeed to fork R2 on my Github

  2. Then get a local repo:
    git clone https://github.com/afaucogney/loopback-sdk-android.git

  3. Add the origin
    git init
    git remote add origin https://github.com/afaucogney/loopback-sdk-android.git

  4. Add the upstream (Strongloop version)
    git remote add origin https://github.com/strongloop/loopback-sdk-android.git

  5. Create local branch
    cd loopback-sdk-android
    git branch firstpr
    git checkout firstpr

Then what to do, I would expect

git rebase origin upstream... but nothing interesting happen.

Please advise me on the process as well as git command.

2

There are 2 answers

0
Anthony On BEST ANSWER

Let see a very detailed worked:

  1. Fork on Github the repo that provide the solution by clicking on "Fork" button:

    enter image description here

    So you get a fork in your Github (called here R3) account like:

    enter image description here

  2. In Github, do a Pull Request:

    enter image description here

    Where:

    • the base repo is the MilleZimTech fix_flatten branch (the one with the solution)
    • the compare repo is the Strongloop (R1) master branch

    Like that (with all the commits done by Strongloop since the Ageneau Fork):

    enter image description here

  3. Click on "Create Pull Request":

    enter image description here

  4. The PR cannot be automatically merged:

    enter image description here

  5. Clone the branch on your local compute (Be careful, the procedure is different that the one proposed by Github). Use --branch <branch-name> to clone a specific branch

    git clone https://github.com/MilleZimTech/loopback-sdk-android.git --branch fix_flatten
    cd loopback-sdk-android
    git branch

    You should see the 'fix_flatten' branch

  6. Create a new branch with the master repo in it:

    git checkout -b strongloop-master fix_flatten git pull https://github.com/strongloop/loopback-sdk-android.git master

    In case of conflict.

    git status shows you the file that are modified or not.
    git add . adds new files.
    git commit -am"merge fix_flatten master" commits the change.
    Again git pull https://github.com/strongloop/loopback-sdk-android.git master

  7. Switch the fix_flatten branch

    git checkout fix_flatten

  8. Merge both branches without FastForward merge

    git merge --no-ff strongloop-master

    You should see :

    enter image description here

  9. Push back to Github repo

    git push origin fix_flatten

  10. In case you clone the repo with git:// and not https:// you need to :

    git remote set-url --push origin https://github.com/MilleZimTech/loopback-sdk-android.git, use the --push' because without, only thefetch` argument of the origin repository will be updated.

    and again git push origin fix_flatten

  11. Then see the changes on Github like

    enter image description here

  12. As this is the fix_flatten branch that is up to date, do a pull request on master branch on my repo.

    Select the fix_flatten branch, then we can see:

    enter image description here

  13. Click on PullRequest

    • base master branch
    • compare fix_flatten branch
  14. Merge and Confirm the PullRequest

    enter image description here

  15. Then you can PullRequest safely Strongloop repo

    enter image description here

End :

Ouuuf... this was hard to find and describe. But I think this can help someone that doesn't know well git. Never the less, I cannot understand why this has been so complicated and long.

Does anyone has a more direct way to do such usual task ?

2
Oscar On

Let me see if I understood correctly. Did you try to fork R2 deleting first the previous forks you don't need anymore?

EDIT: The problem here is that you forked both repos where only the second one is required because is the one which contains the branch you require.

At this point you have two options: 1.- Delete the fork you did on your github account and fork again only R2. 2.- Add R2 as remote and make a git fetch R2 to get those branches that are only on R2.