Languages
[Edit]
EN

Git - get current branch name

8 points
Created by:
Marcin
15680

In this short article we would like to show how to get current active branch name using Git in terminal.

Quick solution:

git symbolic-ref --short HEAD

Output:

master

Alternative solutions

1. git rev-parse example

git rev-parse --abbrev-ref HEAD

Output:

master

2. git status example

git status command returns information about changes that includes active branch name. With head and cut commands we are able to get only branch name.

Example:

git status | head -1 | cut -d ' ' -f 3

Output:

master
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join