how to list remote git branches

How to List Remote Git Branches

Git is a popular version control system that allows large teams to easily build software using distributed version control mechanism, and also supports code branches for independent development. These branches can be maintained on a developer’s local system as well as the main remote repository. Often developers maintain multiple branches in remote repository. Sometimes you may need to list remote git branches to understand what branches are already present in your remote repository. In this article, we will learn some of the different ways to get a list of remote git branches.

How to List Remote Git Branches

Here are some of the ways to list remote git branches.

1. List Remote Branches

The simplest way to list remote branches is the following command.

$ git branch -r

Here is its sample output. Please note, it will precede each branch in the output with name of remote containing the branch.

origin/main
origin/development
origin/testing

Please remember to add -r option in above command, else it will list all local branches present on your local system and not the remote ones.

Also it is advisable to run the following command before you run the above command, since it downloads metadata for all branches in remote repo first.

$ git fetch --all

2. Get Detailed Branch Information

If you want more detailed information about each branch, add -v option in addition to -r option mentioned above.

$ git branch -r -v

It will output each remote branch along with its latest commit and commit message.

origin/main 48a7450 bug fix: css border
origin/development 98b7450 bug fix: center div
origin/testing 6745450 bug fix: js link

3. List Remote References

You can also use ls-remote command to get a list of remote references in a remote repository including remote branches. Here is its syntax, mention remote repository’s name or URL after ls-remote command.

$ git ls-remote [remote_name_or_URL]

Here is its sample output. It basically lists the SHA1 ID of git object reference to each branch along with its currently active branch.

4. Display All Branches

You can also run ‘git branch -a’ command to list all branches (local & remote) available to you.

$ git branch -a

Here is a sample output. It will first list all local branches, followed by all remote branches, prefixed with ‘remote’.

working
*development
main
remote/origin/development
remote/origin/testing
remote/origin/working

In this article, we have learnt several ways to list all remote git branches. You can use any of them as per your requirement.

Also read:

How to Clone Specific Git Branch
How to Checkout File from Another Branch
How to Access This in Arrow Function
How to Access Nested JavaScript Objects
Linux Copy File Permissions from One File to Another

Leave a Reply

Your email address will not be published. Required fields are marked *