How to Get Current Branch in Git
Fumbani Banda
Feb 02, 2024
This tutorial demonstrates how to get the current branch one is working on in git by using the git branch
command and git symbolic-ref
command.
Get Current Branch
Use git branch
command to get a list of all the branches, and the branch name with a star is the current branch.
In the case above, the repository only has one branch, master
, and the asterisk shows we are currently in the master
branch.
Another way to get the current branch is by using the command, git symbolic-ref --short HEAD
. This only displays the current branch. The image below shows that we are in the master
branch.
Author: Fumbani Banda