git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Show all branches and ahead/behind states

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
May 14, 2015, 18:13 UTC
Message-ID
<CAHd499BoApGJSM_qEKG8cHNOV_pOCyPRqEAXHo8iqYVg1LpGdw@mail.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:

Show 29 quoted lines
> 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)
Previous: Dennis KaarsemakerNext: Jeff King
Message 5 of 8 in “Show all branches and ahead/behind states”
  1. Robert DaileyMay 14, 2015
  2. Dennis KaarsemakerMay 14, 2015
  3. Robert DaileyMay 14, 2015
  4. Dennis KaarsemakerMay 14, 2015
  5. Robert DaileyMay 14, 2015
  6. Jeff KingMay 14, 2015
  7. Robert DaileyMay 15, 2015
  8. Jeff KingMay 15, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.