Git
Programming
Git Diff
Command Line
Git Configuration

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:

bash
git --no-pager diff

It is a Git-level flag, so it goes before the subcommand, not after:

bash
1# CORRECT
2git --no-pager diff
3
4# WRONG (fails with: error: invalid option: --no-pager)
5git diff --no-pager

It works with any Git command:

bash
git --no-pager log --oneline -20
git --no-pager show HEAD
git --no-pager blame src/main.py

Permanently, for diff only

To keep the pager for git log and other commands but never for git diff:

bash
git config --global pager.diff false

This writes to your global ~/.gitconfig:

ini
[pager]
    diff = false

You can do the same for any command:

bash
1# Disable pager for diff only
2git config --global pager.diff false
3
4# Disable pager for log only
5git config --global pager.log false
6
7# Disable pager for show only
8git config --global pager.show false

To re-enable the pager:

bash
git config --global --unset pager.diff

Permanently, for all Git commands

bash
git config --global core.pager cat

This replaces the default pager (less) with cat, which just prints to stdout. Your ~/.gitconfig will contain:

ini
[core]
    pager = cat

An empty string also works:

bash
git config --global core.pager ''

Both result in no paging.

For one repository

Useful when a project has long diffs you never want paged:

bash
cd /path/to/repo
git config pager.diff false

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)

bash
1# Disable pager for this terminal session
2export GIT_PAGER=cat
3git diff
4
5# Or inline for a single command
6GIT_PAGER=cat git diff

PAGER (Git and other tools)

bash
export PAGER=cat
git diff
# Also affects: man, less, psql, etc.

Which setting wins

Git checks for a pager in this order (first match wins):

PrioritySourceExample
1 (highest)--no-pager flaggit --no-pager diff
2GIT_PAGER env varexport GIT_PAGER=cat
3core.pager configgit config core.pager cat
4PAGER env varexport PAGER=cat
5 (lowest)System defaultUsually 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:

bash
1# Create an alias for unpaged diff
2git config --global alias.d '!git --no-pager diff'
3
4# Now you can use:
5git d          # no pager
6git diff       # pager (default)

A fuller set:

bash
git config --global alias.d '!git --no-pager diff'
git config --global alias.ds '!git --no-pager diff --staged'
git config --global alias.dl '!git --no-pager log --oneline -20'

In ~/.gitconfig:

ini
1[alias]
2    d = !git --no-pager diff
3    ds = !git --no-pager diff --staged
4    dl = !git --no-pager log --oneline -20

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:

bash
1# Piping to another command: no pager
2git diff | grep "TODO"
3
4# Redirecting to a file: no pager
5git diff > changes.patch
6
7# Piping to less manually: you control the pager
8git --no-pager diff | less -R

Scripts that process git diff output therefore work without any pager configuration:

bash
1#!/bin/bash
2# This script does NOT need --no-pager because output is piped
3changed_files=$(git diff --name-only)
4for file in $changed_files; do
5    echo "Changed: $file"
6done

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:

bash
1# Force color output even without a pager
2git --no-pager -c color.diff=always diff
3
4# Or set it permanently
5git config --global color.diff always

If you want to keep a pager, less -R preserves colors:

bash
git config --global core.pager 'less -R'

If you disable the pager entirely, make sure color.ui is auto (the default) or always:

bash
git config --global color.ui auto

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

MethodScopePersistentAffects other commands
git --no-pager diffSingle commandNoNo
pager.diff falseAll git diff callsYesNo (diff only)
core.pager catAll Git commandsYesYes (all Git)
GIT_PAGER=catCurrent sessionNoYes (all Git)
PAGER=catCurrent sessionNoYes (all tools)
Git aliasPer-aliasYesNo
  • --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 log and 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 diff paged and git d unpaged.

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.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Interview Questions practice on Codemia

Over 11,000 interview practice questions for 300+ companies, searchable by company and role.

Browse interview questions