gitgit-branchgit-clonecollaboration

How can I create a branch in my fork based off a branch in a different fork (of the same master)?


I have my own fork I’ve been working on for awhile:

https://github.com/udance4ever/batocera.linux/

I verified the work done in this branch of a fellow developer’s fork is something I wish to build upon:

https://github.com/bryanforbes/batocera.linux/tree/bryanforbes/macos-build

How do I create my own “Apple-build” branch in my fork that is based off of the above branch in a different fork?

Both forks have the same master:

https://github.com/batocera-linux/batocera.linux/

I’m well aware I could make a “fork of a fork” but I’m still going to run into the issue of how to merge any changes I make in the new fork back into my own original fork (as I don’t anticipate commits being pulled into master anytime soon)

If someone would like to suggest a different workflow that achieves the same goal, please feel welcome to!

What I’ve tried

This answer looked promising so I tried:

git fetch https://github.com/bryanforbes/batocera.linux.git bryanforbes/macos-build

which ends up fetching data into my repository:

remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 48 (delta 24), reused 41 (delta 22), pack-reused 1 (from 1)
Unpacking objects: 100% (48/48), 26.15 KiB | 704.00 KiB/s, done.
From https://github.com/bryanforbes/batocera.linux
 * branch                    bryanforbes/macos-build -> FETCH_HEAD
Fetching submodule buildroot
From https://github.com/batocera-linux/buildroot
   ce59a3e8ce..015766e5a6  br2-external -> origin/br2-external
From https://github.com/batocera-linux/buildroot
 * branch                  c5e38d806a062cd40ccc5c0f000370d9f3c65879 -> FETCH_HEAD

but when I try:

git merge --allow-unrelated-histories bryanforbes/macos-build

I get this error:

merge: bryanforbes/macos-build - not something we can merge

I also can’t seem to switch to the branch:

$ git checkout bryanforbes/macos-build
error: pathspec 'bryanforbes/macos-build' did not match any file(s) known to git

My thinking is if I am able to import the branch into my own repo, I’ll be able to merge the commits into an integration branch and go from there.


Solution

  • Make a fork of a fork:

    git clone https://github.com/bryanforbes/batocera.linux
    

    Switch to desired branch:

    git checkout bryanforbes/macos-build
    

    Create a new branch (based on desired branch):

    git checkout -b Apple-build bryanforbes/macos-build
    

    Change remote origin to your own fork:

    git remote set-url origin https://github.com/udance4ever/batocera.linux.git
    

    Push new branch to your fork (setting the upstream):

    git push --set-upstream origin Apple-build
    

    Result is a branch based on commits in a branch in a different fork and now tracked in your own fork:

    https://github.com/udance4ever/batocera.linux/tree/Apple-build