How do you see which branches are tracking remote branches?
Posted by GraceDv
Last Updated: July 07, 2024
In Git, you can check which local branches are tracking remote branches by using a couple of different commands. Here are the most common ways to see the tracking status:
1. Using git branch -vv
You can use this command to display a list of all local branches along with their tracking status and the corresponding remote branch, if they are tracking one:
git branch -vv
This will show something like:
* main       1234567 [origin/main] Commit message
  feature    89abcde [origin/feature: ahead 2] Commit message
  bugfix     3456789 Commit message
In this output: - The * indicates the current branch. - The part in square brackets [origin/main] shows that the local branch is tracking the origin/main branch. - The : ahead 2 means that the local branch is 2 commits ahead of the remote branch.
2. Using git remote show
You can also use the following command to get detailed information about your remote branches and which local branches are tracking them:
git remote show origin
Replace origin with the name of the remote if it's different. This command will provide output indicating which local branches are configured to track remote branches, along with additional information about the remote repository.
3. Using Configuration File
You can manually check the .git/config file in your repository to see the branch tracking configuration, though this is less common. Look for sections under [branch "branch-name"], which include information about remote and merge. To view this file, you can use a text editor or:
cat .git/config
Summary
The easiest method is to use git branch -vv, but if you want more comprehensive information about remote branches, git remote show origin is very useful too.