Git
git diff
pager
command line
version control

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

By default, git diff usually sends its output through a pager such as less so long diffs are easier to scroll. That is often helpful, but sometimes you want the raw output directly in the terminal, in a file, or in another command pipeline.

Git gives you several ways to disable the pager, depending on whether you want the change for one command, one repository, or your entire user configuration.

Disable The Pager For One Command

The simplest one-off solution is:

bash
git --no-pager diff

This tells Git not to use a pager for that invocation only. It is ideal when you just want to inspect or pipe the output once without changing configuration.

Another temporary option is to override the pager through an environment variable:

bash
GIT_PAGER=cat git diff

This also bypasses paging for that command.

Disable Paging For git diff Permanently

If you consistently prefer raw diff output, configure Git so git diff does not use a pager:

bash
git config --global pager.diff false

That changes the behavior for your user account across repositories.

If you want the setting only in the current repository, omit --global:

bash
git config pager.diff false

This is useful when one repository has a special workflow, such as scripts that rely on unpaged diff output.

Understand The Scope Of The Setting

These approaches have different scopes:

  • 'git --no-pager diff affects only one command'
  • 'GIT_PAGER=cat git diff affects only one command invocation'
  • 'git config pager.diff false affects the current repository'
  • 'git config --global pager.diff false affects your user-level Git configuration'

Choosing the narrowest scope that solves the problem usually keeps your setup easier to reason about.

Why Git Uses A Pager In The First Place

Git uses a pager because diffs can be long. Paging makes it easier to scroll backward, search, and quit without flooding the terminal scrollback.

That means disabling the pager is not always the best default. It is most useful when the output is short, being redirected, or being consumed by another tool. It is also useful when piping the diff into commands such as grep or wc where paging only gets in the way.

A Useful Middle Ground

Sometimes you do not want to disable paging globally, but you do want a command that never pages. In that case, creating an alias can be convenient:

bash
git config --global alias.dn '!git --no-pager diff'

Then you can run:

bash
git dn

This keeps the default Git behavior intact while giving you an explicit no-pager shortcut.

Common Pitfalls

The biggest mistake is changing the global pager setting when the need was only temporary. That can make future long diffs harder to read.

Another pitfall is using git diff > file.txt and forgetting that paging is usually bypassed automatically when output is redirected. In many shells, the command may already behave the way you want without extra configuration.

A third issue is disabling the pager by setting a broad environment variable in your shell startup files without realizing it affects many Git commands, not just git diff.

Summary

  • Use git --no-pager diff for a one-off no-pager diff.
  • Use GIT_PAGER=cat git diff for a temporary environment override.
  • Use git config pager.diff false to disable paging for git diff in one repository.
  • Use git config --global pager.diff false only if you want that behavior everywhere.
  • Prefer the smallest scope that solves the problem.

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.