poke poke - 1 year ago 118
Git Question

Github: Import upstream branch into fork

I have a fork (

) from a project (
) on github. Now the upstream project has added a new branch, I want to import into my fork. How do I do that?

I tried checking out the remote and creating a branch on top of that, but that configures the branch the way that
git push
is trying to push to the

git checkout upstream/branch
git checkout -b branch


Maybe that wasn't clear, but I want to add the branch to my local repository, so I can push it to
(my fork) via
git push
. Because upstream repositories are usually read-only and you fork it to contribute.

So I basically want to checkout a non-existent branch on
whose contents will be pulled in from

Answer Source
  • Make sure you've pulled the new upstream branch into your local repo:
    First, ensure your working tree is clean (commit/stash/revert any changes)
    Then, do git fetch upstream to retrieve the new upstream branch

  • Create and switch to a local version of the new upstream branch (which is named newbranch in this example):
    git checkout -b newbranch upstream/newbranch

  • When you're ready to push the new branch to origin:
    git push -u origin newbranch

The -u switch sets up tracking to the specified remote (in this example, origin)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download