user1809913
user1809913

Reputation: 1865

How do I pull in a new branch from a remote repo?

I forked a repo on github but they than created another branch inside that repo. When I do git fetch upstream it does not create that branch in my repo. How do I do this?

Upvotes: 7

Views: 6020

Answers (2)

Klas Mellbourn
Klas Mellbourn

Reputation: 44377

After you have done git fetch and gotten the new remote branch origin/branchname you can do

git checkout -t origin/branchname

This creates a local branch called branchname that tracks the remote branch.

If you know for sure that the name of the remote branch is exactly origin/branchname, and there is no other branch called branchname on any other remotes you have, you can use the shorthand

git checkout branchname

An alternative syntax can be used if you want to name the local branch something different

git checkout -b local_branchname -t origin/branchname

Upvotes: 11

tessi
tessi

Reputation: 13574

git checkout <branchname>

Git automatically matches the branch names.

Upvotes: 1

Related Questions