5

I have forked a repo into my own github account and have successfully pulled it to my PC, however there is now a new branch on the original repo that I want as well but when I try to fork that branch, it takesme to the master branch on my github account without actually doing anything. How do I get both branches on my account.

bphand95
  • 75
  • 1
  • 6
  • Fetch from wherever you want, the upstream github repo for instance. Add a remote for it rather than just using the url. Communication between repos is entirely arbitrary.. – jthill Mar 20 '16 at 20:02
  • Would this be for use from command line or github? I was trying to get it onto my account then pull it down with command line. I'm very new to git so a lot of the commands are unfamiliar to me. – bphand95 Mar 20 '16 at 20:28
  • 1
    Github's not really where most real work gets done, it's for the meta stuff – jthill Mar 20 '16 at 20:36

1 Answers1

17

Once you have cloned your fork, you can on your local cloned repo add a new remote referencing the original repo (the one you have forked, and the one where a new branch of interest just appeared)

It is the triangular workflow:

https://cloud.githubusercontent.com/assets/1319791/8943755/5dcdcae4-354a-11e5-9f82-915914fad4f7.png

What you do is:

cd /path/to/local/repo
git remote add upstream /url/of/original/repo
git fetch upstream

That last fetch will include the new branch (in the remotes/upstream namespace)

From there, you can easily create a local branch starting from that upstream/newBranch and push it to your fork (referenced by the remote named 'origin')

git checkout -b newBranch upstream/newBranch
git push -u origin newBranch
user12984287
  • 127
  • 5
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250