Languages
[Edit]
EN

Git - get current branch name

8 points
Created by:
Dragontry
731

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

Alternative titles

  1. Git - get active branch name
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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