In this short post today I want to show you have to configure the "pager" for Git and introduce my personal favorite tool for that job.
How Git Looks for a Pager
The documentation for
git config describes the
core.pager setting. It explains Git’s order of preference for determining which program to use for its pager, i.e. the program for displaying the text output of many commands. The order of preference is:
- The value of
- And finally the program
Git defaults to using
less as a last resort although you can change that when compiling Git if you want. Personally I use the first two methods together, which admittedly is a bit redundant. But I like to make my intentions as clear as possible.
My Favorite Git Pager
In the past I wrote about Tig in general and even mentioned its use as a pager. But I did not explain how to configure Git to use it.
Configuring Git to Use Tig
First you can simply set
tig in your shell configuration.
Second, you can globally set
core.pager like so:
git config --global core.pager "tig"
However, you’ll need to do more than that. By default Git will send colored output to pagers. Tig does its own coloring, so you do not want Git to interfere with that or you’ll get some weird output. You can tell Git to not color output to pagers like so:
git config --global color.pager false
I strongly recommend this when using Tig.
Benefits and Conclusion
With those settings in place, running
git log looks like this. What’s nice about this is that I have full access to Tig’s commands from the log output. That means when the cursor is over a commit SHA-1 I can press
d to see the full diff for that commit, or
t to see the tree for that commit, or
b on a filename to see colorized, interactive
git blame output, and so on. In other words, using Tig as a pager for Git gives me more benefits than just some differently colored output.
So if you use Git from the command-line most of the time like I do then try giving Tig a chance as your default pager.