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

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.


The git log --decorate will put by default:

  • the HEAD in cyan
  • the remote branches in red
  • the tag in green

and can be changed through color.decorate config.

But the git log --format don't offer a way to display specifically the HEAD or remotes or branch: all three are displayed through %d, with one color possible.

— VonC on "Color in git-log"