How To Checkout A Remote Branch From Github

As I’ve been pairing recently, my pair created a branch that we can work on. As we added more and more code to the branch, which we pushed to Github, I wanted to check it out locally so I can play around with it and push any necessary changes that I made.

But I had a hard time finding how to do that. Here is how to actually checkout a remote Github branch locally (so you can pull the changes, not just clone the branch):

$ git checkout -b branch_name origin/branch_name

or

You can use the track option to track the remote branch locally. Once you’re tracking it, you can check it out and work on it:

git checkout -t branch_name origin/branch_name

Enjoy the article? Join over 14,500+ Swift developers and enthusiasts who get my weekly updates.

  • So git checkout -b will create a branch on our local repo; given that origin is the github repo.

    But I don’t really get git checkout -t, so basically when we do git add . (or is it already in track?) it will be included in our local repo?