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.
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.
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:
If you made accidental edits:
That force-quits without saving.
Navigating Inside less
Before you exit, you often want to find specific content. Here are the navigation commands that matter most.
| Key | Action |
q | Quit the pager |
j or Down Arrow | Scroll down one line |
k or Up Arrow | Scroll up one line |
Space or f | Scroll down one page |
b | Scroll up one page |
g | Jump to the beginning |
G | Jump to the end |
/pattern | Search forward for "pattern" |
?pattern | Search backward for "pattern" |
n | Next search match |
N | Previous search match |
h | Open 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:
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:
Disable the pager for all Git commands
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:
The flags mean:
| Flag | Effect |
-F | Quit automatically if the output fits on one screen |
-R | Display ANSI color codes (keeps Git's colored output) |
-X | Do 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:
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.):
| Flag | Effect |
-i | Case-insensitive search (unless you type uppercase) |
-M | Show more verbose position info at the bottom |
-R | Interpret ANSI color codes |
-F | Auto-quit if output fits one screen |
-X | Do not clear screen on exit |
This affects every program that uses less, not just Git.
Common Pitfalls
- Pressing
Ctrl+Zinstead ofq. This suspendslessinstead of quitting it. You end up with a stopped process in the background. If you do this accidentally, typefgto bring it back, then pressq. - Typing
qwhile in search mode. If you pressed/to search, pressingqtypes a literal "q" into the search field. PressEscapefirst to cancel the search, then pressq. - Not knowing which pager you are in. If your
core.pageris set tovimormostinstead ofless, the exit key is different. Rungit config --get core.pagerto check. - Using
-Xand wondering why colors disappeared. The-Xflag alone does not preserve colors. You need both-Rand-Xtogether. - Assuming
--no-pagergoes after the subcommand. Writinggit log --no-pagerdoes not work. It must begit --no-pager log.
Summary
- Press
qto exitgit logorgit diff. This works inless, the default Git pager. - Use
Space/bto page down/up,/to search, andn/Nto navigate matches. - Configure
core.pagerto'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 falseto permanently disable the pager for a specific command. - Use
git --no-pager difffor a one-time bypass without changing configuration. - If you are stuck in
viminstead ofless, pressEscapethen type:qand pressEnter.

