tags:

views:

107

answers:

3

I tried looking for a special git command for this but couldn't find one. Can anyone suggest anything shorter or faster than:

git branch | awk '/\*/ { print $2; }'
+1  A: 

I'm using

/etc/bash_completion.d/git

It came with git and provides a prompt with branch name and argument completion.

iny
+1  A: 

You may be interested in the output of

git symbolic-ref HEAD

In particular, depending on your needs and layout you may wish to do

basename $(git symbolic-ref HEAD)

or

git symbolic-ref HEAD | cut -d/ -f3-

and then again there is the .git/HEAD file which may also be of interest for you.

Michael Krelin - hacker
You can shorten `git rev-parse --symbolic-full-name` to `git symbolic-ref`.
earl
Thanks! I'll edit the answer.
Michael Krelin - hacker
You don't need to use `basename` or `cut`; use `BR=${BR#refs/heads/}` (where BR is name of variable you saved output of `git symbolic-ref HEAD`).
Jakub Narębski
Jakub, of course not, provided you have the output in variable.
Michael Krelin - hacker
+5  A: 
$ git rev-parse --abbrev-ref HEAD
master

This should work with Git 1.6.3 or newer.

earl
Doesn't seem to work with my git.
Michael Krelin - hacker
Works with 1.6, though. +1, but I think it would be better if you mention this requirement.
Michael Krelin - hacker
Doesn't work for me either, with git-1.6.2.5. git rev-parse --abbrev-ref HEAD => --abbrev-ref311172491a9a667f9321bdf1c4fe5e22cc6e2c08 (ie rev-parse does not accept --abbrev-ref (not in the man page either))
JasonWoof
JasonWoof, works for me in 1.6.4.2, need to changelog to see when exactly did it happen ;-)
Michael Krelin - hacker
As far as I can tell from the Git logs, this feature was merged in 2009-04-20 and was released with version 1.6.3.
earl