Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fork a new branch from a repo when you already have the master?

Tags:

git

github

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.

like image 635
bphand95 Avatar asked Feb 08 '23 11:02

bphand95


1 Answers

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
like image 187
VonC Avatar answered Feb 14 '23 09:02

VonC