# Feature Request: add a --current option to git branch

3 messages from 2011-02-23 to 2011-02-23. Participants: John Jendro, Jay Soffian, Junio C Hamano.
Thread: https://gitlist.dev/t/26583

## John Jendro, 2011-02-23 19:08

Subject: Feature Request: add a --current option to git branch
Message-ID: <AANLkTimDE18XK8NOg++pxqs5LCJZ4m67Ygo4JvYDbw+F@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimDE18XK8NOg%2B%2Bpxqs5LCJZ4m67Ygo4JvYDbw%2BF%40mail.gmail.com

```
Yes I know this can be done with sed & grep, but --current should be a
standard thing for git branch to have.

-- 

-John Jendro

```

## Jay Soffian, 2011-02-23 19:32

Subject: Re: Feature Request: add a --current option to git branch
Message-ID: <AANLkTikecya+o+rLVHJARv06mCtEv-Ef1nRECQH0saLr@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikecya%2Bo%2BrLVHJARv06mCtEv-Ef1nRECQH0saLr%40mail.gmail.com
In-Reply-To: <AANLkTimDE18XK8NOg++pxqs5LCJZ4m67Ygo4JvYDbw+F@mail.gmail.com>

```
On Wed, Feb 23, 2011 at 2:08 PM, John Jendro <tacliat@gmail.com> wrote:
> Yes I know this can be done with sed & grep, but --current should be a
> standard thing for git branch to have.

I sense you're looking to get the name of the currently checked out
branch, possibly for use in a script. In that case, you may want "git
rev-parse --abbrev-ref HEAD" or "git rev-parse --symbolic-full-name
HEAD" depending upon what you're trying to do.

j.

```

## Junio C Hamano, 2011-02-23 19:47

Subject: Re: Feature Request: add a --current option to git branch
Message-ID: <7vbp228rec.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbp228rec.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTikecya+o+rLVHJARv06mCtEv-Ef1nRECQH0saLr@mail.gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

> On Wed, Feb 23, 2011 at 2:08 PM, John Jendro <tacliat@gmail.com> wrote:
>> Yes I know this can be done with sed & grep, but --current should be a
>> standard thing for git branch to have.
>
> I sense you're looking to get the name of the currently checked out
> branch, possibly for use in a script. In that case, you may want "git
> rev-parse --abbrev-ref HEAD" or "git rev-parse --symbolic-full-name
> HEAD" depending upon what you're trying to do.

And if you are not scripting, then the completion script we ship (it was
originally done for use with bash but I was told that it also can be used
with zsh) may help.

Note that the completion script shows how to do this properly---if you
are indeed scripting, it may be a good idea to study it, but the gist of
it is:

	if b=$(git symbolic-ref HEAD 2>/dev/null)
        then
		echo "You are on branch ${b#refs/heads/}"
	else
		echo "You are not on any branch"
	fi

```
