Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (20 sloc) 461 Bytes
layout title date excerpt categories
Get name of current Git branch
2017-10-11 20:08:32 -4000
How to get the name of the current Git branch.
git branch bash cli

You can get the name of the current Git branch with:

$ git symbolic-ref --short HEAD


$ git rev-parse --abbrev-ref HEAD

And if you wish to assign the name to a variable:

$ current_branch=$(git symbolic-ref --short HEAD)
$ echo $current_branch