How to Check Upstream Tracking Git Branches
This article illustrates how we can see which local branch tracks which remote/upstream branch in a git repository and how you can set up a local branch o track a remote branch.
Check Upstream Tracking Git Branches
We can run the command below to see which local branch is tracking which remote branch.
$ git branch -vv
The double verbose should display all branches in our local repository and their correspondent remote-tracking branches.
Output:
Newer versions of Git will display the remote tracking branches in blue. From the above image, we see that:
- The branch
Dev2.1
is tracking the branchDev2.1
in the upstreamorign
. - The branch
Sample_Branch
is tracking theSample_Branch
branch in the upstreamorigin
. Dev_Branch
,Main-Branch
,main
, andMaster
branches do not have remote tracking branches.
Let’s say we want to set up a remote tracking branch for the Master
branch in one of our upstream above. We can run the following command.
$ git branch -u origin/Master
The above command should set up a remote tracking branch for our Master
branch. Let’s now check, if the Master
branch has a remote tracking branch.
git branch -vv
Output:
Our Master
branch now has a remote tracking branch.
Conclusion
We can run the git branch
command with a double verbose -vv
to see which remote branch is being tracked by a local branch. We have also covered how to add a remote tracking branch to your local branch.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn