Git

How to See Which Git Branches are Tracking Which remote/upstream Branch

Sometimes Git users want to view the details of local and remote branches along with the current status whether they are up to date as upstreaming, tracking branch, or merged branch. You may need these changes in detail to view the other team member’s modifications in the project source code files. Moreover, Git multiple commands can be utilized for this purpose.

This guide will provide different ways to see which Git branches are tracking and which are remote/upstream through multiple Git commands.

How to See Which Git Branches are Tracking Which remote/upstream Branch?

Git provides several commands to see the Git local branch’s status, either as a remote-tracking branch or a remote/upstream branch. Developers can view the merged branches’ details as well through these commands.

Let’s move ahead and practically perform the above-discussed operation to display the list of tracking and upstream remote branches!

Change to Git Local Repository

First, execute the “cd” command and move to the Git local repository:

$ cd "C:\Users\nazma\Git\Test_9"

View Upstream Local Branches

To view the list of local branches names along with SHA hash and their upstreamed status if exist, execute the “git branch -vv” command:

$ git branch -vv

According to the output, our current repository has two branches named “origin/dev” and “origin/master” which are settled as upstream, highlighted in blue color:

Display the List of All Tracked Remote Branches

If you need to display all existing tracked remote branches’ names with tracked status, the below-listed command can be utilized:

$ git remote show origin

Here, our current repository contains the below-highlighted remote branches which are tracked:

Check the Status of Current Local Working Git Branch

Write out the git switch“ command with the local branch name to check the status of the current local working branch:

$ git switch alpha

As you can see, the current working branch is up to date with “remote/<branch-name>”, which indicates that is added as a tracking branch:

View All Existing Tracking and Merged Branches

To show the all existing tracking branches as well as the list of all merged branches, run the “git config –get-regex branch” command:

$ git config --get-regex branch

See the Head of Each Local Branch

To see the head of each local branch, the following command can be executed:

$ git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads

Here, the above command includes:

  • git for-each-ref” command is used to display the head of the local branch.
  • –format=’%(refname:short) <- %(upstream:short)’ refs/heads” option is utilized for showing the local branch name with the upstreamed remote branch name.

As you can see, the below highlighted local branches are added as upstream with remote branches:

We have provided the different commands to see which Git local branches are tracking which remote/upstream branch.

Conclusion

Different Git commands are used to view the Git local branch’s status, either added as a remote-tracking branch or remote/upstream branch, such as the “$ git branch -vv” command can be utilized to view the list of all local branches along with short SHA hash and their current status including the upstream status and many more commands for this purpose. This guide demonstrated different Git commands to see which Git branches are tracking and which remote/upstream branch.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.