Home > Software engineering >  git branch pretty format '%C(always/auto)'
git branch pretty format '%C(always/auto)'

Time:08-28

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?)

CodePudding user response:

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

CodePudding user response:

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

  • Related