Last Updated: February 25, 2016
·
438
· b4hand

Git color even within less

I've always liked Git's color support, but I've had issues with it not working within the default less pager. I personally use less all the time for viewing random files which sometimes contain binary data, and so I like the default behavior in less which is to escape binary data because it keeps my terminal from getting scrambled. However, it turns out that less has perfectly good support for ANSI color, but it is just disabled by default. Recently, I desperately need to paginate through some colored output so I checked the man page for less and found the -R option which does exactly what I wanted for this particular case. However, I didn't want to change the global behavior of less. Fortunately, git as usual has an answer, you can specify a custom pager:

http://git-scm.com/book/en/Customizing-Git-Git-Configuration#Basic-Client-Configuration

Or in my case, I can simply specify an alternate command line option:

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

Make sure you already have color support enabled:

git config --global color.ui true