Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In order to get coloured output from all git commands, I set the following:

git config --global color.ui true

However, this produces an output like this for git diff, git log

git diff screenshot

whereas commands like git status display fine

git status screenshot

Why is it not recognizing the escaped color codes in only some of the commands and how can I fix it?

I'm using iTerm 2 (terminal type xterm-256color) on OS X 10.8.2 and zsh as my shell

zsh --version
zsh 5.0.0 (x86_64-apple-darwin12.0.0)

git --version                                                                                                                      
git version (Apple Git-31.1)
share|improve this question
up vote 46 down vote accepted

You're seeing the escape sequences that tell the terminal to change colors displayed with the escape character shown as ESC, whereas the desired behavior would be that the escape sequences have their intended effect.

Commands such as git diff and git log pipe their output into a pager, less by default. Git tries to tell less to allow control characters to have their control effect, but this isn't working for you.

If less is your pager but you have the environment variable LESS set to a value that doesn't include -r or -R, git is unable to tell less to display colors. It normally passes LESS=-FRSX, but not if LESS is already set in the environment. A fix is to explicitly pass the -R option to tell less to display colors when invoked by git:

git config --global core.pager 'less -R'

If less isn't your pager, either switch to less or figure out how to make your pager display colors.

If you don't want git to display colors when it's invoking a pager, set color.ui to auto instead of true.

share|improve this answer
Ah, thanks. While I knew that less needed -R to display colors, I forgot that git log and git diff piped output to less. Thanks :) – user32465 Feb 16 '13 at 1:10
Thank you! I hadn't noticed that the default ~/.profile in FreeBSD had PAGER=more; export PAGER – Jeffrey Goldberg Mar 3 '14 at 22:26
Thanks. I had LESS set to -K because I like being able to CTRL-C everything. I thought it was something funky with that variable, and now I know how to fix it. – trysis Apr 3 at 13:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.