How to checkout to a remote git branch?

You can use git checkout -b <local_branch_name> <remote_name>/<remote_branch_name> command to checkout to a remote git branch.


Create a new git local repository:

Create your 1st commit in local repository default branch:

Create and add an empty remote repository to your local repository:

Create a new feature branch in your local repository and push it to your remote repository:

This remote feature brach will be used next to demonstrate how to checkout to a remote branch in git. Next, clone the remote repository in some other place and try to switch to the remote feature branch.

Clone the remote repository and create a new local repository from it:

Check all git branches in the new local repository:

Observe: git clone command also copies all remote repository branches. The same goes for git fetch and git pull.

Checkout to a remote repository branch:

Create the second commit in the feature branch and push the changes:

Delete both the local repository and remote repository.

Leave a Reply