Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+7 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

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?

1 Answer

+10 votes
by (27.5k points)

For Git versions ≥ 1.6.6, with only one remote:

git fetch
git checkout test

Remember that git checkout test won’t work in modern git if you have multiple remotes. In this case use:

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

or use the shorthand

git checkout -t <name of remote>/test

git checkout remote branch - How do I check out a remote Git branch?
Intellipaat-community
by (29.3k points)
git checkout -b test <name of remote>/test this worked for me.
by
Your answer was very helpful!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...