Get name of current Git branch


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

git symbolic-ref --short HEAD

Or:

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


Please support this site and join our Discord!