Stop git diff using a pager: git --no-pager and pager config
Codemia Knowledge Hub ·
Run git --no-pager diff to skip the pager for a single command. To turn it off permanently for git diff, run git config --global pager.diff false. Other options apply the change per session, per repository or to every Git command.
One command: the --no-pager flag
--no-pager makes Git print straight to the terminal instead of routing output through less or another pager:
It is a Git-level flag, so it goes before the subcommand, not after:
It works with any Git command:
Permanently, for diff only
To keep the pager for git log and other commands but never for git diff:
This writes to your global ~/.gitconfig:
You can do the same for any command:
To re-enable the pager:
Permanently, for all Git commands
This replaces the default pager (less) with cat, which just prints to stdout. Your ~/.gitconfig will contain:
An empty string also works:
Both result in no paging.
For one repository
Useful when a project has long diffs you never want paged:
Without --global, the setting goes into that repository's .git/config only.
For the current session: environment variables
Environment variables control paging for the current terminal session without touching config files.
GIT_PAGER (Git only)
PAGER (Git and other tools)
Which setting wins
Git checks for a pager in this order (first match wins):
| Priority | Source | Example |
| 1 (highest) | --no-pager flag | git --no-pager diff |
| 2 | GIT_PAGER env var | export GIT_PAGER=cat |
| 3 | core.pager config | git config core.pager cat |
| 4 | PAGER env var | export PAGER=cat |
| 5 (lowest) | System default | Usually less |
Per-command config (pager.diff) overrides core.pager for that command. If the pager behaves unexpectedly, check all of these sources: a GIT_PAGER variable, for example, overrides core.pager in your config.
An alias for unpaged diffs
To keep both paged and unpaged diffs handy without typing --no-pager:
A fuller set:
In ~/.gitconfig:
The ! prefix is required: it runs the alias as a shell command. Without it, the alias syntax does not support the --no-pager flag position.
Pipes and redirects skip the pager automatically
Git disables the pager when output is piped or redirected, so --no-pager is redundant there:
Scripts that process git diff output therefore work without any pager configuration:
Keeping colors without a pager
With the pager disabled, Git may also drop colors because it detects output going to a non-terminal (or assumes colors only matter with a pager). To force colors:
If you want to keep a pager, less -R preserves colors:
If you disable the pager entirely, make sure color.ui is auto (the default) or always:
With auto, Git colors output going to a terminal and drops colors when piped or redirected, which is what most workflows want.
Choosing a method
| Method | Scope | Persistent | Affects other commands |
git --no-pager diff | Single command | No | No |
pager.diff false | All git diff calls | Yes | No (diff only) |
core.pager cat | All Git commands | Yes | Yes (all Git) |
GIT_PAGER=cat | Current session | No | Yes (all Git) |
PAGER=cat | Current session | No | Yes (all tools) |
| Git alias | Per-alias | Yes | No |
--no-pager: you normally want the pager but occasionally need unpaged output. Good for one-off commands and scripts.pager.diff false: you never want a pager for diffs. The most targeted option;git logand others are unaffected.core.pager cat: you want no paging anywhere in Git. Common with tmux or terminals that have good scrollback.GIT_PAGER=cat: scripts and CI pipelines that need clean, non-interactive output for the whole job.- Aliases: you want both,
git diffpaged andgit dunpaged.
The most common mistake is putting --no-pager after the subcommand (git diff --no-pager). The second is confusing pager.diff, which only affects git diff, with core.pager, which affects every command.
Related reading
- How do I programmatically determine if there are uncommitted changes?
- How do I properly force a Git push?
- How do I provide a username and password when running \"git clone [email\_protected]\"?
- How do I pull from a Git repository through an HTTP proxy?
- How do I push a local Git branch to master branch in the remote?
- How do I push a local repo to Bitbucket using SourceTree without creating a repo on bitbucket first?
- How do I push a new local branch to a remote Git repository and track it too?
- How do I push amended commit to the remote Git repository?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.