Languages
[Edit]
EN

Git - get current branch name

8 points
Created by:
Marcin
2465

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
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.