Search code examples
gitpushparent-childgit-forkupstream-branch

How to edit/push/pull the parent of a parent fork on GitHub


For a project I am using a Python package called Efficientnet-pytorch-3d (this github page). This 3D implementation is forked from a 2D implementation called Efficientnet-pytorch (this github page). The fork order on github is like this:

lukemelas/EfficientNet-PyTorch -> shijianjian/EfficientNet-PyTorch-3D/ ->  nwschurink/EfficientNet-PyTorch-3D

As you can see I forked the 3D implementation of the package to my own GitHub as I needed to add some functionality that I was missing. I changed the code and performed a pull request to the shijianjian/Efficientnet-Pytorch-3D repo to merge this into the master.

Ok, so now my problem. On the issue page of the 2D Efficientnet-pytorch GitHub I found someone who is asking for the functionality that I have added to the 3D implementation. I can easily add this to the code, however since the 2D and 3D code are now quite different it's not possible to just perform a pull request for the changes that I made to the Efficientnet-PyTorch-3D code. Apparently it is impossible to also fork lukemela/EfficientNet-PyTorch into my github...

How do I pull the code from the original repo (lukemelas/EfficientNet-PyTorch) to my GitHub, make the changes and then push it to lukemelas/EfficientNet-PyTorch ?

I can only find guides on howto push your code to the parent of the fork that I have (e.g. to shijianjian/EfficientNet-PyTorch-3D), but I cannot seem to find how to get to the parent's parent.


Solution

  • Here how I will handle it.

    Add an upstream

    git remote add upstream_2D git@github.com:lukemelas/EfficientNet-PyTorch.git
    

    Fetch the content

    git fetch upstream_2D
    

    Create a branch pointing to the upstream master (or the last common ancestor see below).

    git checkout -b mySuperFix  upstream_2D/master
    

    Do your patch here and submit your Pull Request

    Then merge this branch to your master branch if you want and if it is possible.

    Some commits from the 2D project are not merged into the 3D one, the 3D fork seems to not have been kept sync with the 2D project.

    So I think you should based your work on the last common ancestor:

    git checkout -b mySuperFix  d8481a539cc1f84ef0fe502f9c12dcc187669611
    

    This can be easier, or you can start by merging the 2D commit into the 3D project then make your commit based on 2D master