15

I've two remotes - origin which points to my fork and upstream which points to company repo.

$git remote -v origin https://github.com/me/app.git (fetch) origin https://github.com/me/app.git (push) upstream https://github.com/company/app.git (fetch) upstream https://github.com/company/app.git (push) 

I forked before a month. and I've been pushing to origin and then raising a pull request to upstream. This was fine.

Now someone created a branch called "3D_Theory" in upstream and I want to first reflect that new branch in to my origin and then work off of that branch. But for some reason that branch is not reflecting in my origin.

I tried the following:

git remote show origin >> does not list 3D_Theory git remote show upstream >> lists 3D_Theory 

I tried:

git fetch upstream git checkout master git merge upstream/3D_Theory 

But still I don't have that branch created on my fork. How can I get a new branch on upstream to reflect on my fork?

Thank you

None of the following similar problems helped me:

1

5 Answers 5

26

Yay, I guess this worked.

git fetch upstream 3D_Theory:3D_Theory git status git push origin 3D_Theory 

If you have a better solution please post it here and I'll try your solution and mark it as the better answer.

Sign up to request clarification or add additional context in comments.

1 Comment

This solution doesn't work for some projects as you can get these errors if the repo is too big: stackoverflow.com/questions/44780221/… So JamesP solution is actually the better way to do this.
13

This can now be done via the GitHub UI. Select the Code<> tab and then click Branches. Add a new branch and change the source to the upstream repository. Select the new branch you want to add to your own fork and give the branch the same name as the upstream one.

From now on you can use the Sync Fork button to update your branch with the upstream one.

3 Comments

Other git fetch upstream didn't work for me. This approach in the GUI worked in adding a new branch to my fork from the original repository. Ty!
Best answer for me, as it's easier that the CLI solution
On GitHub UI I found I had to create a new branch in my fork with same name as upstream repository and then Sync fork
4

Above will fetch only specified branch. There could be many newly branches created, if team size is large. This can be accomplished by following steps.

  1. This will fetch all upstream branches & show on terminal

    git fetch upstream

  2. This will push the current branch to upstream

    git push origin

2 Comments

This did not work for me after forking an organization's repo which contained a branch besides the default one. I was unable to get git fetch upstream to give me a reference to said non-default branch.
Before that add the "upstream": git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git and check with git remote -v
0

This worked for me

Ensure you added upstream such that

git remote -v shows the upstream branch that you forked from too

To sync/pull all the new branches from upstream do

git fetch upstream --prune

This should pull all the new branches

Comments

0

You should first update the remote:

git remote update 

Then try to checkout to that remote branch(in your case the forked one):

git checkout --track upstream/3D_Theory 

Now you should be checked out to 3D_Theory branch in your local. Happy Coding :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.