How to checkout a remote git branch

Ever happened to you that someone in the team pushes a new branch to the remote git repository and they you want to checkout their branch?

How to checkout a remote git branch

Image from unity3d.college

Ever happened to you that someone in the team pushes a new branch to the remote git repository and they you want to checkout their branch?

If you have you should have experienced that a simple “git checkout branchname” will not work!

To do that, if you have only one remote repository, you can do the following:

git fetchgit checkout branch_name

Not if you have multiple “remotes” the above command will not work and you need to use the following command instead:

git checkout -b branch_name <remote repo name>/branch_name

or a shorter version would be

git checkout -t <remote repo name>/branch_name

If you use GIT regularly, I recommend to get this book and have it on your desk:

Pro Git
Pro Git (Second Edition) is your fully-updated guide to Git and its usage in the modern world. Git has come a long way…www.amazon.com

If you liked this article, click the👏 below so other people will see it here on Medium.

Let’s be friends on Twitter. Happy Coding :)

Cheers!