Image by Cianna Woods from Pixabay

Git-Config: core.pager

How to Wrangle Git’s Terminal Output

Karl Stolley
4 min readFeb 3, 2022

--

For many users, one of Git’s more confusing defaults is its use of a pager for displaying output from commands like git log and git branch. Depending on your operating system’s configuration, Git might open a pager screen even when a command like git config --global --list returns far less than a screen’s worth of output:

Terminal output showing configuration values in a pager.

To exit from the pager (which defaults on most systems to less), you have to hit the Q key. Obvious only if known, am I right?

Numerous other Git commands make use of the pager, including such fundamentals as git branch, git diff, and git log.

Customizing core.pager

Image generated on PicturetoPeople

If you loathe pagers, you’ll want to customize the core.pager configuration value. I tend to be somewhat anti-pager myself, often because I want to see Git’s output back on the command line to, say, reference a specific commit hash. Paged output disappears when you quit the pager. There are a few ways to modify Git's default paging behavior.

The first is to simply set core.pager to an empty string:

$ git config --global core.pager ""

A more explicit value would be cat, which writes output straight to the command line. The effect appears the same as the empty string:

$ git config --global core.pager "cat"

Here is the same output from thegit branch command above, but now it’s displayed in the context of the entire terminal session:

Terminal output showing configuration values in context.

Using less -FX

Image generated on PicturetoPeople

Pagers are useful when working with something like a massive diff. One flexible configuration approach is to set your core.pager to the value less -FX, which will present output in a pager only when the output is longer than one terminal screen (if you’re running less version 530 or higher, you can simply set less -F):

$ git config --global core.pager "less -FX"

That’s a solid compromise if you prefer to have a pager available only on multipage output.

Using Other Pager Settings

Image generated on PicturetoPeople

You can always disable a pager when running a command by adding --no-pager after the git command but before the subcommand you actually want to run:

$ git --no-pager branch

If you prefer a finer-tuned approach to paging, you can set your general preference on core.pager, and then set pager.* values to suit your preference for specific commands.

For example, if you generally don’t like a pager except when viewing diffs longer than a single terminal screen, you can do this:

$ git config --global core.pager "cat"
$ git config --global pager.diff "less -FX"

With that configuration, output from all of Git’s commands will be dumped out to the command line—care of cat—but git diff will move to a pager for diffs longer than a screen. Shorter diffs still appear in context:

Terminal output showing a short diff in context.

Summing Up

In this post, we’ve looked at:

  • Customizing core.pager
  • Using less -FX
  • Adding--no-pager
  • Setting pager.* values for your needs

In the next post, we’ll look at changing the output on diffs themselves, from the simple two-color, +/- scheme above to one that uses multiple colors to distinguish genuinely added and removed lines from lines that have simply been moved, copied, and even indented differently.

Karl Stolley’s book, Programming WebRTC: Build Real-Time Streaming Applications for the Web, is available in beta from The Pragmatic Bookshelf. You can save 35 percent with promo code git_config_2022 now through March 31, 2022. Promo codes are not valid on prior purchases.

--

--

Karl Stolley
The Pragmatic Programmers

Author of Programming WebRTC, out in beta at Pragmatic Programmers. Chicagoan. Developer & writer.