Git: force colourization with color.ui or --color

By default, Git only colourizes in its output when writing to an interactive terminal. Sometimes, this heuristic isn’t accurate, for example, when you’re piping Git output through another command. In such cases, you can force colourization on or off with either the color.ui configuration option or the --color option. Let’s look at both in turn.
The color.ui configuration option
You can control colourization in general with the color.ui configuration option. For a single command, set it with git -c:
$ git -c color.ui=never branch
Or set it globally with git config:
$ git config --global color.ui always
I wouldn’t set the option globally on a development machine, but it can be useful on CI systems that support ANSI colour codes.
color.ui takes three possible values:
never: turn off colourization.always: turn on colourization.auto: the default, use colourization when writing to an interactive terminal.
Some commands have their own colourization options, which override color.ui. For example, the color.branch option can be set to control whether git branch colourizes its output. It’s rare to want such fine-grained control, but it’s there if you need it.
The --color option
Some Git commands accept a --color option to force colourization, for example, git log. This can be a little more convenient for one-off commands, but it’s only a limited subset of commands that support it.
Use bare --color to force colourization on:
$ git log --color
Or --color=never to force colourization off:
$ git log --color=never
Or --color=auto to select the default behaviour:
$ git log --color=auto
The main commands which accept a --color option, at time of writing, are:
git diffgit loggit showgit tag
😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸
One summary email a week, no spam, I pinky promise.
Related posts:
- Git: Improve conflict display with the
zdiff3style - Git: avoid
reset --hard, usereset --keepinstead - Git: Show the initial (root) commit
Tags: git