How To Checkout Remote Git Branch?

Git provides remote branches in order to collaborate with others. The git checkout command is used to checkout remote branches. The collaborated repositories are hosted in the remote Git servers and used by other developers.

Fetch Remote Branch Information

First, we will fetch and update remote branch information. The git fetch command with the --all option.

$ git fetch --all
Fetch Remote Branch Information

Check Remote Branch

After receiving the remote branch information we can check out the remote branch. The remote branches are listed in the previous step like origin/master . In the following example we checkout the remote branch named “origin/master”.

$ git checkout origin/master

Checkout Remote Branch As New Branch In Local

Alternatively, we can check out the remote branch into a new local branch by creating it. The git checkout command is used with the following syntax.

git checkout -b NEW_LOCAL_BRANCH REMOTE_BRANCH

In the following example, we check out the remote branch named origin/master into the new local branch named testing .

$ git -b testing origin/master

Leave a Comment