Languages
[Edit]
EN

Git - get current branch name

8 points
Created by:
Dragontry
431

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

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join