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

Here are commands:

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

// After fetching all branches, checkout branch
git checkout branch1
or
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.

git clone <repository-url>
git branch -r
git checkout branch-name
git