Git is a version control system used by software developers and teams to keep track of changes made to the codebase of a software project.
In Git, a remote upstream branch is a branch on a remote repository that is being tracked by a local branch in your local repository.
If you are working on a team project, or if you have forked a repository, it is important to know which branches in your local repository are tracking which remote upstream branches.
In this tutorial, we’ll show you how to see which Git branches are tracking which remote upstream branches.
Checking a Single Branch
To check which remote upstream branch a local branch is tracking, you can use the following Git command in your terminal:
$ git branch -vv
The -vv
option will show you the name of the remote repository, the name of the remote upstream branch, and the last commit made to the remote upstream branch.
Here’s an example of the output you’ll see:
* master d670460 [origin/master] added readme file
In this example, the master
branch is tracking the remote upstream branch origin/master
on the remote repository origin
.
The last commit made to the remote upstream branch was d670460
.
Checking All Branches
If you want to check the upstream branch for all branches in your local repository, you can use the following Git command:
$ for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
This command will show you the name of each remote upstream branch, the date and time of the last commit made to the remote upstream branch, the name of the author of the last commit, and the name of the local branch that is tracking the remote upstream branch.
Here’s an example of the output you’ll see:
2022-12-22 12:32:12 -0800 3 months ago Jane Doe origin/feature/readme
2022-11-25 12:24:35 -0800 5 months ago John Doe origin/feature/about
2022-10-17 12:14:12 -0800 7 months ago Jane Doe origin/feature/home
In this example, the local branch feature/readme
is tracking the remote upstream branch origin/feature/readme
, the local branch feature/about
is tracking the remote upstream branch origin/feature/about
, and the local branch feature/home
is tracking the remote upstream branch origin/feature/home
.
Conclusion
Knowing which Git branches are tracking which remote upstream branches is important for understanding the relationships between branches in your local repository and branches on remote repositories.
By using the Git commands shown in this tutorial, you can easily see which branches in your local repository are tracking which remote upstream branches.