Git FAQ
Frequently asked questions around Git and Version Control.
Git FAQ featured image

git checkout a Remote Branch

One of the first Git commands you've learned was certainly "git checkout":

$ git checkout development

In its simplest form, it allows you to switch (and even create) local branches - something you need countless times in your day-to-day work.

However, git checkout's power is not limited to local branches: it can also be used to create a new local branch from a remote one.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Collaborating with Branches

Remember that branches are the main way of collaboration in Git. Let's say that one of your colleagues wants you to collaborate on (or review) a piece of code:

  1. She will push the corresponding branch to your common remote server.
  2. In order to see this newly published branch, you will have to perform a simple "git fetch" for the remote.
  3. Using the "git checkout" command, you can then create a local version of this branch - and start collaborating!

git checkout for Remote Branches

The syntax for making git checkout "remote-ready" is rather easy: simply add the "--track" flag and the remote branch's ref like in the following example:

$ git checkout --track origin/newsletter
Branch newsletter set up to track remote branch newsletter from origin.
Switched to a new branch 'newsletter'

Based on the remote branch "origin/newsletter", we now have a new local branch named "newsletter".

Note that, by default, Git uses the same name for the local branch. Being a good convention, there's rarely the need to change this.


Tip

Checking Out Remote Branches in Tower

In case you are using the Tower Git client, tracking a remote branch is as easy as drag and drop:

Committing and Exchanging Data

From here on, you can make changes and commit them to your new local branch like you're used to.

Remember to publish your changes to the remote by using "git push" from time to time. Only then will your colleague(s) be able to see and understand your changes.


Learn More

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.