How to Check Upstream Tracking Git Branches

John Wachira Feb 15, 2024
  1. Check Upstream Tracking Git Branches
  2. Conclusion
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:

display all branches in our local repository and their correspondent remote tracking branches

Newer versions of Git will display the remote tracking branches in blue. From the above image, we see that:

  1. The branch Dev2.1 is tracking the branch Dev2.1 in the upstream orign.
  2. The branch Sample_Branch is tracking the Sample_Branch branch in the upstream origin.
  3. Dev_Branch, Main-Branch, main, and Master 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:

set up remote tracker branch for the master branch

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.

Author: John Wachira
John Wachira avatar John Wachira avatar

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

Related Article - Git Branch