Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Can I get less not to monochrome its output?

E.g., the output from git diff is colored, but git diff | less is not.

share|improve this question
possibly the same on superuser: superuser.com/questions/117841/… –  Ciro Santilli 六四事件 法轮功 Sep 19 '14 at 8:08

4 Answers 4

up vote 84 down vote accepted


git diff --color=always | less -r

--color=always is there to tell git to output color codes even if the output is a pipe (not a tty). And -r is there to tell less to interpret those color codes and other escape sequences. Use -R for ANSI color codes only.

share|improve this answer
Excellent! Can I translate this to a "git config --global" command? –  ripper234 Aug 24 '11 at 12:23
@ripper234. With recent gits, git config color.ui true should be enough to obtain colored output, and to automatically run a pager for long outputs. –  Stéphane Gimenez Aug 24 '11 at 12:48
True enough, I was actually using something similar but not quite like it. Thanks anyway for the great answer. –  ripper234 Aug 24 '11 at 13:20
@ripper234 you can set an alias for this: unix.stackexchange.com/a/50007/24272 –  AvL Oct 5 '12 at 8:23
In parallel to this Q/A, watch --color 'git diff --cached --color=always' and its friends can bring you some additional awesomeness. –  Alois Mahdal Jul 26 '13 at 9:19

Another option would be to enable colors and use 'less -r' as your pager.

git config --global color.ui true
git config --global core.pager 'less -r'

This results in

    ui = true
    pager = less -r

in your ~/.gitconfig

For more information see the Pro Git book.

share|improve this answer

Use -r (--raw-control-chars) option to less, or also -R (only ANSI escape sequences).

I have an alias for this in ~/.bashrc

alias rless='less -r'
share|improve this answer
Actually I just did alias less='less -r'. Any reason not to? –  ripper234 Aug 24 '11 at 12:25
@ripper234: I vaguely remember there could be cases when using -r when not needed can lead to visualization problem. –  enzotib Aug 24 '11 at 12:29
For instance, when you pipe ack with less -r you lose a carriage return –  New Alexandria Jan 14 '13 at 15:58
You can just use \less if visualization messes up. –  Bepetersn Oct 26 '13 at 0:41

Just to add another version on the "use less -r":

use the environment variable LESS with the value r (or add r to whatever it already is)

eg, as I use it in my .bashrc

  export LESS=-Xr

(The X stops the screen from clearing when exiting less)

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.