Last Updated: February 25, 2016
·
579
· colindean

Get the current git branch

git symbolic-ref --short -q HEAD

Remove --short and you'll get the full one, e.g. ref/heads/master.

This is even more useful when added as an alias in your ~/.gitconfig:

[alias]
  current-branch = symbolic-ref --short -q HEAD

4 Responses
Add your response

The option --short is not available on git version 1.7.1 (which is the default for many RHEL based systems outhere (CentOS 6 etc...).

over 1 year ago ·

oh-my-zsh git plugin is super productive! check it out.

over 1 year ago ·

I just type

git branch

over 1 year ago ·

too

over 1 year ago ·