How to checkout a branch from a remote git repo

by Melvin Ram

Conversation from IRC #git channel

melvinram: I am working on a new machine and I’ve got a git repo inside github. I’ve just pulled it down and it’s currently on the master branch. How do I get it to pull down branch xyz and have it checkout? Is it: git checkout -b xyz origin/xyz

jnareb: melvinram: fetch, then either create tracking local branch reflecting remote-tracking branch, or directly checkout which would detach HEAD

jnareb: melvinram: that is one solution, and I guess the one you would want; unless you want to only “take a look”

jnareb: “git checkout -b branch remote/branch” (which creates local tracking branch), or “git checkout remote/branch” (which detaches HEAD -> you are on ‘no branch’)

Leave a Comment