EN
Git - get current branch name
8
points
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