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
Written by Colin Dean
Related protips
4 Responses

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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#