How to achieve separate colors for current, local, and remote ref names when using a custom git log format

colorsgit

I have a custom git log format that I use. I have color.ui=true set in my .gitconfig. For example this simple format:

git log --pretty=format:"%h %d %s" --decorate

This would print something like

52a41e0 (HEAD, local) Commit message foo
185bd17 (remote) The commit message

HEAD, local, remote will be output without color compared to git log --oneline --decorate which will outupt HEAD (in 'bold cyan'), local (in 'bold green') and remote (in 'bold red') with color. Now I can wrap the %d with something like %Cred%d%Creset which will cause all ref names to be red.

How can I get current, local, and remote ref names to have seperate colors when using a custom format with git log?

Best Answer

You can now use %C(auto) as of git 1.8.3, according to this Atlassian blog post;

git log --format=format:'%h%C(auto)%d%C(reset) %s (%an, %ar)'

gives

enter image description here

— Again, courtesy of VonC on "Color in git-log", reposted here for the convenience of inbound googlers.