Skip to content
Fix Code Error

How do I check out a remote Git branch?

March 13, 2021 by Code Error
Posted By: Anonymous

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 test which does nothing

  • git checkout origin/test gives * (no branch). Which is confusing. How can I be on “no branch”?

How do I check out a remote Git branch?

Solution

With One Remote

Jakub’s answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can do:

git fetch
git checkout test

As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use

git checkout -b test <name of remote>/test

or the shorthand

git checkout -t <name of remote>/test

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:

git fetch origin

This will fetch all of the remote branches for you. You can see the branches available for checkout with:

git branch -v -a

With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:

git checkout -b test origin/test
Answered By: Anonymous

Related Articles

  • Why do I have to "git push --set-upstream origin "?
  • Why do git fetch origin and git fetch : behave differently?
  • Rails wrong number of arguments error when generating…
  • Why call git branch --unset-upstream to fixup?
  • Git - Pushing code to two remotes
  • Git Using Remote Branch
  • Difference between git checkout --track origin/branch and…
  • How can I find the location of origin/master in git, and how…
  • Checkout another branch when there are uncommitted changes…
  • What exactly does the "u" do? "git push -u origin master" vs…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I convert a String to an int in Java?

Next Post:

How do I check if a string contains a specific word?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error