List All Remote Branches in Git

Abdul Jabbar Feb 06, 2022
List All Remote Branches in Git

Git is specifically known as a distributed version control system with no central server where we push our code. Despite this, we push and pull our desired changes directly to and from other repositories where we want in a branch. It allows us an opportunity to branch out from the original codebase anytime. It enables us to work with other developers more easily and gives us a lot of flexibility in our workflow in a team.

You can have several local repositories on different machines and push them to the same remote repository when the work is finished. This lets us clone the repository on one machine to our second machine and work on it from there as well.

Remote-tracking branches are local branches that track remote branches. They are local pointers to our remote repository, and they can be used easily to switch to a remote branch quickly. The command git remote can be used to create them (they are created with the --track option), and they can be used like any other local branch. It is usually created with the following command.

git branch --track <remote-branch> <local-branch>

The --track option can be added to the git branch command using which we can track the branch commits as well, the command is following:

git branch --track <remote-branch> <local-branch>.

List Git Remote Branch

This section will discuss how to list all the remote branches in Git. We can list the remote branches associated with multiple commands listed below. There are various commands in Git that will display different types of branches depending on your current situation in the repository.

We will use the git branch command to see local branches. The git branch -a command lists local branches and remote-tracking branches that we have set up to keep in sync with remote branches. The git branch -r command lists remote-tracking branches but not local branches. The git remote show command can also list remote branches. The syntax for the list branches in Git is following.

git branch -a 

The syntax for the git branch -r command is below.

git branch -r

The git remote show command syntax is,

git remote show [name]

Where, name is the name of a remote branch in a repository. To see remote branches connected with the master branch in our remote origin repository, use the following command:

git branch -r origin/master

We’ll use the below command to see remote-tracking branches connected with the master branch in our remote origin repository.

git branch -a origin/master

We can say, to see remote branches that aren’t tracked by the local repository, add the-a flag.

git remote show origin -a * remote origin 

If we have a lot of remote branches, we may find it useful to limit the output to only tracked remote branches using the following command.

git remote show origin --tracked * remote origin
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Branch

Related Article - Git Remote