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:
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:
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:
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:
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:
See the Head of Each Local Branch
To see the head of each local branch, the following command can be executed:
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.