How to Get Current Branch in Git

Fumbani Banda Feb 02, 2024
How to Get Current Branch in Git

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.

git_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.

git_branch2

Fumbani Banda avatar Fumbani Banda avatar

Fumbani is a tech enthusiast. He enjoys writing on Linux and Python as well as contributing to open-source projects.

LinkedIn GitHub

Related Article - Git Branch