How do I prevent 'git diff' from using a pager?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Use git --no-pager diff to run git diff without a pager for a single command. To disable the pager permanently for all git diff output, run git config --global pager.diff false. There are several other approaches depending on whether you want the change to apply once, per-session, per-repo, or globally.
One-Time: --no-pager Flag
The --no-pager flag tells Git to print output directly to the terminal without routing it through less or any other pager:
Important: --no-pager goes before the subcommand, not after. This is a Git-level flag, not a diff flag.
This works for any Git command, not just diff:
Permanent: Disable Pager for diff Only
If you always want git diff to print directly but still want the pager for git log and other commands:
This sets the configuration in your global ~/.gitconfig:
You can do this for any Git command individually:
To re-enable the pager later:
Permanent: Disable Pager for All Commands
To disable the pager for every Git command globally:
This replaces the default pager (less) with cat, which simply prints everything to stdout. Your ~/.gitconfig will contain:
Alternatively, set it to an empty string:
Both achieve the same result: no paging.
Per-repository configuration
For a single repository (useful when a project has long diffs you never want paged):
Without --global, the setting goes into .git/config in that repository only.
Session-Based: Environment Variables
Environment variables let you control paging for the current terminal session without changing any configuration files.
GIT_PAGER (affects Git only)
PAGER (affects Git and other tools)
Priority order
Git checks for a pager setting 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 specific command.
Using Aliases for Convenience
If you want the option to run both paged and unpaged diffs without typing --no-pager:
For a more complete setup:
These go into ~/.gitconfig:
Piping and Redirecting Output
Git automatically disables the pager when output is piped or redirected. You do not need --no-pager in these cases:
This means scripts that process git diff output work correctly without any pager configuration:
Keeping Colors Without a Pager
When you disable the pager, Git may also disable color output because it detects that output is going to a non-terminal (or it assumes colors are only useful with a pager). To force colors:
A more common approach is to use less -R as the pager, which preserves colors:
But if you are disabling the pager entirely, this is not relevant. Just make sure color.ui is set to auto (the default) or always:
With auto, Git enables colors when output goes to a terminal and disables them when piped or redirected. This is the correct behavior for most workflows.
Comparison of All Methods
| 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 |
When to Use Which Method
Use --no-pager when you occasionally need unpaged output but normally want the pager. Good for one-off commands and scripting.
Use pager.diff false when you never want a pager for diffs specifically. This is the most targeted option and does not affect git log or other commands.
Use core.pager cat when you prefer no paging for any Git command. Common for developers who use tmux or terminal emulators with good scrollback.
Use GIT_PAGER=cat in scripts and CI pipelines where you want clean, non-interactive output for the duration of a job.
Use aliases when you want both options available: git diff for paged, git d for unpaged.
Common Pitfalls
- Placing
--no-pagerafter the subcommand.git diff --no-pagersilently ignores the flag. It must begit --no-pager diff. This is the most common mistake. - Setting
core.pagerto empty string and losing colors. An empty pager can cause Git to think output is not going to a terminal, disabling colors. Setcolor.ui autoor usecatas the pager instead. - Forgetting that pipes auto-disable the pager. If your diff output is piped to
grep,wc, or redirected to a file, Git already skips the pager. Adding--no-pageris redundant in that case. - Using
--no-pagerin Git aliases incorrectly. Inside a Git alias, you need the!prefix to run a shell command:alias.d = !git --no-pager diff. Without!, the alias syntax does not support the--no-pagerflag position. - Confusing
pager.diffwithcore.pager.pager.diff falseonly affectsgit diff.core.pager cataffects all commands. Know which one you want before setting it. - Not realizing the priority order. A
GIT_PAGERenvironment variable overridescore.pagerin your config. If the pager behaves unexpectedly, check all four sources (flag, env var, command config, global config).
Summary
git --no-pager diffis the quickest way to run a single diff without a pager. The flag must go beforediff.git config --global pager.diff falsepermanently disables the pager fordiffwhile keeping it for other commands.git config --global core.pager catdisables the pager for all Git commands globally.- Environment variables (
GIT_PAGER,PAGER) provide session-level control without modifying config files. - Git automatically disables the pager when output is piped or redirected. No extra flags needed in scripts.
- Git checks
--no-pager, thenGIT_PAGER, thencore.pager/pager.<cmd>, thenPAGER, then falls back toless. - Create aliases like
git dfor a convenient unpaged diff shortcut alongside the normal pagedgit diff.
Related reading
- How do I prevent 'git diff' from using a pager?
- 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 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?
.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 courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.