This tutorial will help you to list remote branches available on the remote git repository. It is helpful you to find names of branches, which have been created on the remote repository by someone and you want to check out this on your local repository.

Advertisement

Method 1: Fetch Remote Tracking Branches

Firstly run git fetch command to update your remote-tracking branches under refs/remotes/<remote_name>/.

git fetch

Now use following command to list all branches on local and all remote repositories.

git branch -a 

//output

* development
  master
  staging
  remotes/origin/development
  remotes/origin/master
  remotes/origin/staging

Method 2: Git List Remote Branches

You can also use ls-remote option to list remote repositories without updating your remote-tracking branches.

git ls-remote 

//output

5ffcb8136c48423f858e49c2df78fc7ac419fe39        HEAD
5ffcb8136c48423f858e49c2df78fc7ac419fe39        refs/heads/development
5ffcb8136c48423f858e49c2df78fc7ac419fe39        refs/heads/master
5ffcb8136c48423f858e49c2df78fc7ac419fe39        refs/heads/staging

If repository connected with multiple remotes, use the following command syntax.

git ls-remote --heads <remote_name>

You can find more details about git ls-remote from here.

Share.

2 Comments

Leave A Reply