How do I prevent 'git diff' from using a pager?

As a previous answer mentioned, passing the -F option to less causes it to quit if the content is less than one screen. However, after doing so, the screen is reset, and you end up not seeing the content.

The -X option does away with that behaviour. So, I use the following to enable conditional paging based on the amount of content:

git config --global --replace-all core.pager "less -F -X"

Use

git config --global core.pager cat

to get rid of a pager for all commands for all repositories.

You can also disable paging for single Git subcommands by using pager.<cmd> setting instead of core.pager, and you can change your settings per Git repository (omit --global).

See man git-config and search for pager.<cmd> for details.


--no-pager to Git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen.

Usage:

git --no-pager diff

Other options from the comments include:

# Set an evaporating environment variable to use 'cat' for your pager
GIT_PAGER=cat git diff

# Tells 'less' not to paginate if less than a page
export LESS="-F -X $LESS"
# ...then Git as usual
git diff

Tags:

Git