gitgithubgit-pushgit-fork

Multiple destination repos to push from forked repo


I have the following.

    Base Repo
    - main
    MyFork Repo (from Base Repo)
    - main
    - feature A
    - feature B
    AnotherFork Repo (from Base Repo)
    - main
    - feature C

I have forked MyFork Repo from Base Repo. That works fine. Now I'm interesting in the feature C branch from AnotherFork Repo. I can't fork AnotherFork Repo because I already forked Base Repo.

I also can't just clone AnotherFork Repo and create branches there or push to feature C. That is just with PRs possible.

Can I do then i.e. something like that?

    MyFork Repo
    - main
    - feature A (is linked to Base Repo)
    - feature B (is linked to Base Repo)
    - feature C (is linked to AnotherFork Repo)

Or do I have to delete MyFork Repo and create then a fork to AnotherFork Repo?


Solution

  • There are two typical workflows: central and distributed.

    Central repository

    Git: central repository

    In this workflow, there is a central / "official" repository from all other pull and push. In this workflow, you'd push feature/C from AnotherFork to Base and then pull feature/C from Base to MyFork.

    $ cd AnotherFork
    $ git push feature/C
    
    $ cd MyFork
    $ git fetch && git switch feature/C
    

    Distributed repositories

    Git: Distributed repositories

    In this workflow, some repositories know others as remotes, and you can directly pull feature/C from AnotherFork to MyFork.

    $ cd MyFork
    $ git remote add AnotherFork proto://url/AnotherFork
    $ git fetch AnotherFork
    $ git switch remotes/AnotherFork/feature/C
    

    Additional reading