Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.
Now I'm trying to check out the remote test branch.
I've tried:
-
git checkout testwhich does nothing -
git checkout origin/testgives* (no branch). Which is confusing. How can I be on "no branch"?
How do I check out a remote Git branch?
Best Solution
With One Remote
Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can do:
As user masukomi points out in a comment,
git checkout testwill NOT work in modern git if you have multiple remotes. In this case useor the shorthand
With >1 Remotes
Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.
To fetch a branch, you simply need to:
This will fetch all of the remote branches for you. You can see the branches available for checkout with:
With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:
I also created the image below for you to share the differences, look at how to fetch works, and also how it's different to pull: