1

I'm trying to create an alias for a particular view of my git branches, with the usual verbose data plus some extra. (Datetime; I'm also sorting by date.) This is possible with a custom format string, but it loses the default coloring from git branch -v; the active branch doesn't get highlighted in green and other coloring like upstreams doesn't show up either. It looks to me from git docs like this should be fixed by adding %C(always) as a prefix to the format string, but this doesn't seem to work:

git branch --format=:%C(always) %(committerdate:short) %(refname:short) %(contents:lines=1)"

just displays

%C(always) 2022-08-23 foo/bar testing Token
%C(always) 2022-08-26 seethefnords fix validation

with no color. What is wrong here?

(Also, just incidentally, is it possible to get the smart alignment back in a custom format string?)

jkmartin
  • 153
  • 1
  • 7

2 Answers2

1

just displays

%C(always) 2022-08-23 foo/bar testing Token

Then the first thing to check is your Git version.

%C(always) was introduced with Git commit 4261775, Git 2.22 (Q2 2019).
Which means you might be using an older Git version.

git version
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Here's a short answer: git branch does not obey the pretty format directives you've linked. Those are for git log only.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Why not? Where is this documented? – jkmartin Aug 29 '22 at 18:03
  • (1) You'll need to ask the Git authors. (2) The `git branch` documentation refers one to the `git for-each-ref` documentation, which describes its (different) formatting directives. – torek Aug 29 '22 at 23:12