Git and libgit2
Mike Slinn

The Git Pager

Published 2023-03-12.
Time to read: 2 minutes.

This page is part of the git collection, categorized under Git.

By default, the git commands that might generate lots of output use a pager, so you can scroll through voluminous output easily. These commands include:

  • git branch -l
  • git config --list
  • git diff
  • git log
  • Help output

The default pager is less. To exit from less, you must press the q key, which is confusing for some people. You can specify any shell command to use as the git pager.

Many options exist for controlling the git pager. I prefer to use the last method shown.

Pipes Do Not Use a Pager

A pager is never used if you pipe the git output to another process, or into a file.

Shell
$ git -P log > my_log.txt
$ git -P diff | grep 'pattern'

Control One Git Command

To control the git pager for just one git command, you have 2 options:

Disable With -P

Pass the -P option to git, before the subcommand, like this:

Shell
$ git -P log
... lots of output... 
$ git -P diff ... lots of output...

Define GIT_PAGER Inline

Control the pager by definoing the GIT_PAGER environment variable inline (before the command).

To disable the pager for the output of the current command only, set GIT_PAGER=cat, like this:

Shell
$ GIT_PAGER=cat git log
... lots of output... 
$ GIT_PAGER=cat git diff ... lots of output...

To use a pager only if the output of the current command is longer than one terminal screen, set GIT_PAGER="less -F", like this:

Shell
$ GIT_PAGER="less -F" git log
... lots of output... 
$ GIT_PAGER="less -F" git diff ... lots of output...

Control Current Shell or Script

To disable the pager for all git commands in the current shell or script, define GIT_PAGER=cat on a separate line, like this:

Shell
$ export GIT_PAGER=cat
$ git branch -l ... lots of output...
$ git log ... lots of output...

To use a pager only if the output of the current command is longer than one terminal screen in the current shell or script, define GIT_PAGER="less -F" on a separate line, like this:

Shell
$ export GIT_PAGER="less -F"
$ git branch -l ... lots of output...
$ git log ... lots of output...

Control Current Project

These methods only affects the copy of the git repository that you are working on; other clones of the repository are not affected.

To permanently configure git to never use a pager for the current git project, configure this project’s configuration for core.pager to have value "cat".

Shell
$ git config core.pager "cat"
$ git branch -l ... lots of output...
$ git log ... lots of output...

To configure git to always use a pager if the output of a git command is longer than one terminal screen in the current project, configure this project’s configuration for core.pager to have value "less -F", like this:

Shell
$ git config core.pager "less -F"
$ git branch -l ... lots of output...
$ git log ... lots of output...

Global Control

This method only affects the git repositories that your OS userid works on; other users are not affected.

You can permanently configure git to never use a pager for any of your git projects.

Shell
$ git config --global core.pager "cat"
$ git branch -l ... lots of output...
$ git log ... lots of output...

My Favorite

To permanently configure git to only use a pager if the output of any git command is longer than one terminal screen in any project, configure the global setting of core.pager to have value "less -F", like this:

Shell
$ git config --global core.pager "less -F"
$ git branch -l ... lots of output...
$ git log ... lots of output...


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.