# Show all branches and ahead/behind states

8 messages from 2015-05-14 to 2015-05-15. Participants: Robert Dailey, Dennis Kaarsemaker, Jeff King.
Thread: https://gitlist.dev/t/39335

## Robert Dailey, 2015-05-14 14:57

Subject: Show all branches and ahead/behind states
Message-ID: <CAHd499AyEDNM7mDstFugD0Ah46=gAS=BRocDmpmOK-1k+qMCmw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499AyEDNM7mDstFugD0Ah46%3DgAS%3DBRocDmpmOK-1k%2BqMCmw%40mail.gmail.com

```
Is there a script or built-in functionality in git 2.4.1 that will
allow me to list all local branches with the ahead and behind status
of each? Basically the first line of:

$ git status -sb

But for every branch would be roughly what I'm looking for. Any ideas? Thanks.

```

## Dennis Kaarsemaker, 2015-05-14 15:55

Subject: Re: Show all branches and ahead/behind states
Message-ID: <1431618938.31573.3.camel@kaarsemaker.net>
URL: https://gitlist.dev/e/1431618938.31573.3.camel%40kaarsemaker.net
In-Reply-To: <CAHd499AyEDNM7mDstFugD0Ah46=gAS=BRocDmpmOK-1k+qMCmw@mail.gmail.com>

```
On do, 2015-05-14 at 09:57 -0500, Robert Dailey wrote:
> Is there a script or built-in functionality in git 2.4.1 that will
> allow me to list all local branches with the ahead and behind status
> of each? Basically the first line of:
> 
> $ git status -sb
> 
> But for every branch would be roughly what I'm looking for. Any ideas? Thanks.

git branch -v (or -vv) is what you're after.
-- 
Dennis Kaarsemaker
www.kaarsemaker.net

```

## Robert Dailey, 2015-05-14 17:18

Subject: Re: Show all branches and ahead/behind states
Message-ID: <CAHd499CQTW0J6ms+XYUBbyfT6gGKuiFFCiP57i8-eTwng+UzNQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499CQTW0J6ms%2BXYUBbyfT6gGKuiFFCiP57i8-eTwng%2BUzNQ%40mail.gmail.com
In-Reply-To: <1431618938.31573.3.camel@kaarsemaker.net>

```
On Thu, May 14, 2015 at 10:55 AM, Dennis Kaarsemaker
<dennis@kaarsemaker.net> wrote:
> On do, 2015-05-14 at 09:57 -0500, Robert Dailey wrote:
>> Is there a script or built-in functionality in git 2.4.1 that will
>> allow me to list all local branches with the ahead and behind status
>> of each? Basically the first line of:
>>
>> $ git status -sb
>>
>> But for every branch would be roughly what I'm looking for. Any ideas? Thanks.
>
> git branch -v (or -vv) is what you're after.
> --
> Dennis Kaarsemaker
> www.kaarsemaker.net
>

Nice, I never noticed that -v showed ahead/behind status. Would be
nice if branch had a --format option to customize the coloring of the
"ahead" / "behind" text so that there was more contrast. It's a lot of
information to consume especially with a lot of local branches;
coloring would bring some sanity.

Thanks!

```

## Dennis Kaarsemaker, 2015-05-14 17:29

Subject: Re: Show all branches and ahead/behind states
Message-ID: <1431624587.31573.5.camel@kaarsemaker.net>
URL: https://gitlist.dev/e/1431624587.31573.5.camel%40kaarsemaker.net
In-Reply-To: <CAHd499CQTW0J6ms+XYUBbyfT6gGKuiFFCiP57i8-eTwng+UzNQ@mail.gmail.com>

```
On do, 2015-05-14 at 12:18 -0500, Robert Dailey wrote:
> On Thu, May 14, 2015 at 10:55 AM, Dennis Kaarsemaker
> <dennis@kaarsemaker.net> wrote:
> > On do, 2015-05-14 at 09:57 -0500, Robert Dailey wrote:
> >> Is there a script or built-in functionality in git 2.4.1 that will
> >> allow me to list all local branches with the ahead and behind status
> >> of each? Basically the first line of:
> >>
> >> $ git status -sb
> >>
> >> But for every branch would be roughly what I'm looking for. Any ideas? Thanks.
> >
> > git branch -v (or -vv) is what you're after.
> > --
> > Dennis Kaarsemaker
> > www.kaarsemaker.net
> >
> 
> Nice, I never noticed that -v showed ahead/behind status. Would be
> nice if branch had a --format option to customize the coloring of the
> "ahead" / "behind" text so that there was more contrast. It's a lot of
> information to consume especially with a lot of local branches;
> coloring would bring some sanity.

Fortunately for you, git for-each-ref lets you do just this. For
example, this gives you what branch -vv does, minus coloration and
padding:

git for-each-ref --format '%(HEAD) %(refname:short) %(upstream:short) %(upstream:track) %(subject)' refs/heads

-- 
Dennis Kaarsemaker
www.kaarsemaker.net

```

## Robert Dailey, 2015-05-14 18:13

Subject: Re: Show all branches and ahead/behind states
Message-ID: <CAHd499BoApGJSM_qEKG8cHNOV_pOCyPRqEAXHo8iqYVg1LpGdw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499BoApGJSM_qEKG8cHNOV_pOCyPRqEAXHo8iqYVg1LpGdw%40mail.gmail.com
In-Reply-To: <1431624587.31573.5.camel@kaarsemaker.net>

```
On Thu, May 14, 2015 at 12:29 PM, Dennis Kaarsemaker
<dennis@kaarsemaker.net> wrote:
> On do, 2015-05-14 at 12:18 -0500, Robert Dailey wrote:
>> On Thu, May 14, 2015 at 10:55 AM, Dennis Kaarsemaker
>> <dennis@kaarsemaker.net> wrote:
>> > On do, 2015-05-14 at 09:57 -0500, Robert Dailey wrote:
>> >> Is there a script or built-in functionality in git 2.4.1 that will
>> >> allow me to list all local branches with the ahead and behind status
>> >> of each? Basically the first line of:
>> >>
>> >> $ git status -sb
>> >>
>> >> But for every branch would be roughly what I'm looking for. Any ideas? Thanks.
>> >
>> > git branch -v (or -vv) is what you're after.
>> > --
>> > Dennis Kaarsemaker
>> > www.kaarsemaker.net
>> >
>>
>> Nice, I never noticed that -v showed ahead/behind status. Would be
>> nice if branch had a --format option to customize the coloring of the
>> "ahead" / "behind" text so that there was more contrast. It's a lot of
>> information to consume especially with a lot of local branches;
>> coloring would bring some sanity.
>
> Fortunately for you, git for-each-ref lets you do just this. For
> example, this gives you what branch -vv does, minus coloration and
> padding:
>
> git for-each-ref --format '%(HEAD) %(refname:short) %(upstream:short) %(upstream:track) %(subject)' refs/heads

Great idea. For some reason I can't apply coloring though:

for-each-ref --format '%(HEAD) %(refname:short) %C(bold
blue)%(upstream:track)%C(reset)' refs/heads

Output:

hotfix/4.2.3.1 %C(bold blue)[ahead 1, behind 1]%C(reset)

```

## Jeff King, 2015-05-14 22:38

Subject: Re: Show all branches and ahead/behind states
Message-ID: <20150514223827.GB21149@peff.net>
URL: https://gitlist.dev/e/20150514223827.GB21149%40peff.net
In-Reply-To: <CAHd499BoApGJSM_qEKG8cHNOV_pOCyPRqEAXHo8iqYVg1LpGdw@mail.gmail.com>

```
On Thu, May 14, 2015 at 01:13:15PM -0500, Robert Dailey wrote:

> > git for-each-ref --format '%(HEAD) %(refname:short) %(upstream:short) %(upstream:track) %(subject)' refs/heads
> 
> Great idea. For some reason I can't apply coloring though:
> 
> for-each-ref --format '%(HEAD) %(refname:short) %C(bold
> blue)%(upstream:track)%C(reset)' refs/heads
> 
> Output:
> 
> hotfix/4.2.3.1 %C(bold blue)[ahead 1, behind 1]%C(reset)

It's spelled "%C(bold blue)" in the --pretty formats, but in
for-each-ref, it's "%(color:bold blue)". Unifying these is one of those
things that has been on the radar for a long time, but nobody has quite
gotten around to it.

-Peff

```

## Robert Dailey, 2015-05-15 14:25

Subject: Re: Show all branches and ahead/behind states
Message-ID: <CAHd499Am4PFo-YRJEbQfPqtk571f4eNr_gkdy-3ATzyvBcc-jw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd499Am4PFo-YRJEbQfPqtk571f4eNr_gkdy-3ATzyvBcc-jw%40mail.gmail.com
In-Reply-To: <20150514223827.GB21149@peff.net>

```
On Thu, May 14, 2015 at 5:38 PM, Jeff King <peff@peff.net> wrote:
> On Thu, May 14, 2015 at 01:13:15PM -0500, Robert Dailey wrote:
>
>> > git for-each-ref --format '%(HEAD) %(refname:short) %(upstream:short) %(upstream:track) %(subject)' refs/heads
>>
>> Great idea. For some reason I can't apply coloring though:
>>
>> for-each-ref --format '%(HEAD) %(refname:short) %C(bold
>> blue)%(upstream:track)%C(reset)' refs/heads
>>
>> Output:
>>
>> hotfix/4.2.3.1 %C(bold blue)[ahead 1, behind 1]%C(reset)
>
> It's spelled "%C(bold blue)" in the --pretty formats, but in
> for-each-ref, it's "%(color:bold blue)". Unifying these is one of those
> things that has been on the radar for a long time, but nobody has quite
> gotten around to it.
>
> -Peff

Thanks Jeff! That definitely fixed it. I was not able to find a
reference for this in the git docs, maybe I just overlooked it
somewhere.

As a second query, is there a way to do column alignment? For example,
I would like the ahead/behind status in one column, and the branch
names left aligned in a 2nd column. I can't simply use tabs here since
the length of column 1 may differ more greatly than a single tab
character.

I imagine there is no built in way to do this, but just curious. I'd
probably end up having to write some complicated script :-(

Thanks again you've been super helpful.

```

## Jeff King, 2015-05-15 16:59

Subject: Re: Show all branches and ahead/behind states
Message-ID: <20150515165912.GA26853@peff.net>
URL: https://gitlist.dev/e/20150515165912.GA26853%40peff.net
In-Reply-To: <CAHd499Am4PFo-YRJEbQfPqtk571f4eNr_gkdy-3ATzyvBcc-jw@mail.gmail.com>

```
On Fri, May 15, 2015 at 09:25:22AM -0500, Robert Dailey wrote:

> > It's spelled "%C(bold blue)" in the --pretty formats, but in
> > for-each-ref, it's "%(color:bold blue)". Unifying these is one of those
> > things that has been on the radar for a long time, but nobody has quite
> > gotten around to it.
> >
> Thanks Jeff! That definitely fixed it. I was not able to find a
> reference for this in the git docs, maybe I just overlooked it
> somewhere.

It's in "git help for-each-ref" (see the section on "FIELD NAMES").

> As a second query, is there a way to do column alignment? For example,
> I would like the ahead/behind status in one column, and the branch
> names left aligned in a 2nd column. I can't simply use tabs here since
> the length of column 1 may differ more greatly than a single tab
> character.

The "--pretty" format does have "%<" for doing printf-style alignment
(see the "PRETTY FORMATS" section of "git help log"). But "for-each-ref"
doesn't have any similar facility, as far as I know.

Again, this is something that it would be nice to fix.

-Peff

```
