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.