Pager
Changing pagination behavior for git
What is it?
Basic non-paging behavior lets you view all output at once (which can be very long like for git log
).
The pager behavior gives you a paginated view (more user-friendly where you can scroll to output or search). Similar to running git log | less
.
Switching paging on and off
- You can switch the behavior using a CLI flag for
git
. - You cn a value in your global git config, for an area like branches or log. This was generally off for me on Bash (besides
git log
) and when switching to ZSH on macOS, I found it was configured on.
More on switching below in various situations.
Generic usage
Turn pager on or off for any command.
Relevant flags for git
-p, --paginate
- Turn on paging.-P | --no-pager
- Turn off paging.
Note that the order is important. Use the flag between git
and the subcommand.
$ git --no-pager SUBCOMMAND [OPTIONS]
Note that some subcommands have -p
as a flag which means something else. So you could do:
$ git -p log -p
See sections below for usage examples.
Branch usage
Global config
$ git config --global pager.branch false
CLI flag
Use a flag to use pager or not ignoring the global config
$ git --no-pager branch
$ git --paginate branch
That is similar to:
$ git branch | cat # Print output
$ git branch | less # Paginate
Log usage
Global config
$ git config --global pager.log false
CLI flag
Log can be very long, so limit it.
$ git --no-pager log --oneline -40
Or with lol
git alias.
$ git --no-pager lol -40
These long comamnds can be aliased as well.
Why have both modes
The non-page behavior I guess might be better for a CI flow (when you want to log output from any command and there is no interactive view).
I don’t see an advantage of using the non-page behavior for writing to a file or piping to another command, as the behavior seems identical from my testing.
Using both modes will load the the entire from the git command and pipe it to the next:
$ git -p log | sed 's/feat:/✨ feat:/g'
$ git -P log | sed 's/feat:/✨ feat:/g'
Confirming that writing to a file with both approaches gives the same result:
$ git -p log > test.text
$ git -P log > test2.text
$ vimdiff # Says no difference.