Git Checkout a Remote Branch - Step by Step Guide

During last 4-5 years, git has captured the market for version control system completely. Here are step by step guide about how to checkout a git remote branch.

Git checkout remote branch - already cloned repository

If you already have a git repository clone locally and you want to checkout a remote branch, you can follow following steps

  • Fetch all branches from remote repository first
  • Once you have all remote branches fetched, you can checkout a particular branch by creating a local branch from remote branch.

Here are commands:

// fetch all branches from remote repository
git fetch origin
git fetch

// After fetching all branches, checkout branch
git checkout branch1
git checkout -b branch1 origin/branch1

You can also use a command to see if a remote branch is available locally or not.

git branch -r

Git checkout remote branch - new repository

If you don't have a local clone of the repository already available, then you will have to first clone the repository.

  • Clone the repository
git clone <repository-url>
  • When you clone the repository, all remote branches at that moment are already fetched. You can see a list of all remote branches by typing
git branch -r
  • To checkout a particular remote branch, just use
git checkout branch-name
Category: git