Git
Programming
Git Diff
Command Line
Git Configuration

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.

Browse interview questions

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:

bash
git --no-pager diff

Important: --no-pager goes before the subcommand, not after. This is a Git-level flag, not a diff flag.

bash
1# CORRECT
2git --no-pager diff
3
4# WRONG (ignored silently)
5git diff --no-pager

This works for any Git command, not just diff:

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

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:

bash
git config --global pager.diff false

This sets the configuration in your global ~/.gitconfig:

ini
[pager]
    diff = false

You can do this for any Git command individually:

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 later:

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

Permanent: Disable Pager for All Commands

To disable the pager for every Git command globally:

bash
git config --global core.pager cat

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

ini
[core]
    pager = cat

Alternatively, set it to an empty string:

bash
git config --global core.pager ''

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):

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

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)

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 (affects Git and other tools)

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

Priority order

Git checks for a pager setting 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 specific command.

Using Aliases for Convenience

If you want the option to run both paged and unpaged diffs 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)

For a more complete setup:

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'

These go into ~/.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

Piping and Redirecting Output

Git automatically disables the pager when output is piped or redirected. You do not need --no-pager in these cases:

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

This means scripts that process git diff output work correctly 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

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:

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

A more common approach is to use less -R as the pager, which preserves colors:

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

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:

bash
git config --global color.ui auto

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

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

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-pager after the subcommand. git diff --no-pager silently ignores the flag. It must be git --no-pager diff. This is the most common mistake.
  • Setting core.pager to empty string and losing colors. An empty pager can cause Git to think output is not going to a terminal, disabling colors. Set color.ui auto or use cat as 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-pager is redundant in that case.
  • Using --no-pager in 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-pager flag position.
  • Confusing pager.diff with core.pager. pager.diff false only affects git diff. core.pager cat affects all commands. Know which one you want before setting it.
  • Not realizing the priority order. A GIT_PAGER environment variable overrides core.pager in your config. If the pager behaves unexpectedly, check all four sources (flag, env var, command config, global config).

Summary

  • git --no-pager diff is the quickest way to run a single diff without a pager. The flag must go before diff.
  • git config --global pager.diff false permanently disables the pager for diff while keeping it for other commands.
  • git config --global core.pager cat disables 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, then GIT_PAGER, then core.pager/pager.<cmd>, then PAGER, then falls back to less.
  • Create aliases like git d for a convenient unpaged diff shortcut alongside the normal paged git diff.

Related reading
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
Track 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.

Browse interview questions

All Rights Reserved.