Somebody pushed a branch called test
with git push origin test
to a shared repository. I can see the branch with git branch -r
.
Simply run git checkout
with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:
git fetch
git checkout test
However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:
git checkout --track origin/test
or
git checkout -b test origin/test
In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.