Git
Git Commands
Git Log
Git Diff
Programming Tools

How to exit git log or git diff

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Press q to exit git log or git diff. Both commands open their output in a terminal pager (usually less), and q is the standard quit key for that pager. Once you know that, the rest of this article covers navigation, customization, and alternatives that make working with Git output significantly more productive.

Why Git Opens a Pager

When git log or git diff produces output longer than your terminal window, Git pipes it through a pager program so you can scroll through it comfortably. The default pager on most systems is less. You never asked for it explicitly. Git just does it automatically when the output is long enough.

This is controlled by Git's core.pager configuration. If you have never changed it, Git uses less. On some systems it may fall back to more, which behaves similarly but has fewer features.

bash
# Check which pager Git is using
git config --get core.pager

If that returns nothing, Git is using the system default, which is almost always less.

How to Exit the Pager

The standard exit: press q

This is the single most important thing to remember. When you see the colon (:) prompt at the bottom of the screen, press q and you are back at your normal terminal.

 
# You see something like this at the bottom of the screen:
:
# Just press q

Force quit with Ctrl+C

Ctrl+C sends an interrupt signal. It works in less, but it is not the intended exit mechanism. Use it only if q is unresponsive for some reason.

If you are stuck in vim instead of less

Some Git configurations set the pager to vim. If you see ~ characters along the left edge, you are in vim, not less. To exit:

 
# Press Escape first, then type:
:q
# and press Enter

If you made accidental edits:

 
:q!

That force-quits without saving.

Before you exit, you often want to find specific content. Here are the navigation commands that matter most.

KeyAction
qQuit the pager
j or Down ArrowScroll down one line
k or Up ArrowScroll up one line
Space or fScroll down one page
bScroll up one page
gJump to the beginning
GJump to the end
/patternSearch forward for "pattern"
?patternSearch backward for "pattern"
nNext search match
NPrevious search match
hOpen help screen

Searching inside git log

Searching is one of the most useful features. If you are looking at a long commit history and need to find a specific commit message:

bash
# Inside the pager, type:
/fix login bug
# Press Enter, then n to jump through matches

This is often faster than quitting and re-running git log --grep.

Customizing the Pager

Disable the pager entirely for specific commands

If you prefer raw terminal output for git log or git diff:

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

Disable the pager for all Git commands

bash
git config --global core.pager cat

This replaces less with cat, which just dumps output straight to the terminal. Useful for scripting, but you lose scrollback and search.

Use the pager but keep output visible after quitting

By default, less clears the screen when you quit. To keep the output visible in your terminal scrollback:

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

The flags mean:

FlagEffect
-FQuit automatically if the output fits on one screen
-RDisplay ANSI color codes (keeps Git's colored output)
-XDo not clear the screen when exiting

This combination is widely recommended because it gives you the best of both worlds: short output prints directly, long output gets paged, and everything stays visible after you exit.

One-time pager bypass with --no-pager

If you want to skip the pager for a single command without changing any configuration:

bash
git --no-pager log --oneline -20
git --no-pager diff

Note that --no-pager goes before the subcommand, not after.

Setting Default less Options via Environment Variable

You can configure less behavior globally through the LESS environment variable. Add this to your shell profile (.bashrc, .zshrc, etc.):

bash
export LESS='-iMRFX'
FlagEffect
-iCase-insensitive search (unless you type uppercase)
-MShow more verbose position info at the bottom
-RInterpret ANSI color codes
-FAuto-quit if output fits one screen
-XDo not clear screen on exit

This affects every program that uses less, not just Git.

Common Pitfalls

  • Pressing Ctrl+Z instead of q. This suspends less instead of quitting it. You end up with a stopped process in the background. If you do this accidentally, type fg to bring it back, then press q.
  • Typing q while in search mode. If you pressed / to search, pressing q types a literal "q" into the search field. Press Escape first to cancel the search, then press q.
  • Not knowing which pager you are in. If your core.pager is set to vim or most instead of less, the exit key is different. Run git config --get core.pager to check.
  • Using -X and wondering why colors disappeared. The -X flag alone does not preserve colors. You need both -R and -X together.
  • Assuming --no-pager goes after the subcommand. Writing git log --no-pager does not work. It must be git --no-pager log.

Summary

  • Press q to exit git log or git diff. This works in less, the default Git pager.
  • Use Space/b to page down/up, / to search, and n/N to navigate matches.
  • Configure core.pager to 'less -FRX' for the best default experience: short output prints directly, long output pages, and nothing disappears when you quit.
  • Use git config --global pager.log false to permanently disable the pager for a specific command.
  • Use git --no-pager diff for a one-time bypass without changing configuration.
  • If you are stuck in vim instead of less, press Escape then type :q and press Enter.

Course illustration
Course illustration

All Rights Reserved.