Setting git's Pager

By default, git sets the pager for things like git diff ... to less. This is a good default, but if less is set to default values, the output of a git diff ... command can be pretty seriously ugly.

Black and white text with inverted video escape codes

Above is what you get as output from something like git diff HEAD^ HEAD. git diff is putting colour codes into less, but in its default configuration, it doesn't know how to handle them. Do this:

git config --global core.pager "less -MR "

"-R" allows less to interpret "raw" control characters (like colour codes). "-M" is less important, but puts more information (like current line number and length of file) into the less prompt at the bottom of the page. After that, your git diff output will look like this:

Properly colourized git diff output in less

This can also be dealt with at the Bash level if you prefer: in your ~/.bashrc file, add the line export LESS="MR" . I generally prefer this, but it depends what system I'm on.