Git Reference ยท Environment Variables
GIT_EDITOR and GIT_PAGER
Reference for GIT_EDITOR, GIT_SEQUENCE_EDITOR and GIT_PAGER: how Git picks an editor and pager, the lookup order, and how to script commits without prompts.
Git starts an editor whenever it needs you to write text: commit messages, tag annotations, git rebase -i todo lists, git notes edit, git commit --amend. It starts a pager when output is longer than a screen. Both programs are chosen from environment variables first, then configuration, then sensible defaults.
GIT_EDITOR overrides everything else for the editor, and GIT_PAGER does the same for the pager. They are the quickest way to change the behavior for a single command, and the standard tool for scripts and tests that must never block waiting for a human.
GIT_EDITOR=true git commit --amend # accept the old message, no editor GIT_PAGER=cat git log # never page GIT_SEQUENCE_EDITOR=: git rebase -i HEAD~3 # accept the default todo list
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
GIT_EDITOR=<command> git <command> GIT_SEQUENCE_EDITOR=<command> git rebase -i ... GIT_PAGER=<command> git <command>
| Name | Description |
|---|---|
GIT_EDITOR |
Command used for every edit Git launches. Highest priority. May contain arguments; it runs through the shell and receives the file name as its last argument. |
GIT_SEQUENCE_EDITOR |
Used only for the todo list of git rebase -i (and --autosquash runs). Falls back to the normal editor. |
GIT_PAGER |
Command that receives long output on its standard input. Setting it to cat disables paging. |
PAGER |
Fallback for the pager when GIT_PAGER and core.pager are unset. |
VISUAL, EDITOR |
Fallbacks for the editor, in that order, after GIT_EDITOR and core.editor. |
Editor lookup order: GIT_EDITOR, core.editor, VISUAL, EDITOR, then the compiled-in default (usually vi). If the terminal is "dumb" and nothing is configured, Git refuses to start an editor and asks you to set one.
Pager lookup order: GIT_PAGER, core.pager, PAGER, then less. Git also sets LESS=FRX and LV=-c if they are unset, so less quits on short output and passes colors through.
Edge cases: an editor that exits with a non-zero status aborts the operation. An empty commit message aborts the commit. GIT_PAGER="" (empty) also disables paging.
Usage notes
- No editor in scripts: use
-mfor messages, orGIT_EDITOR=trueto accept whatever Git pre-filled (trueexits 0 without touching the file).:works as well. - Pager only when attached to a terminal: Git skips the pager when standard output is a pipe or file, so
git log | headand CI logs are already unpaged.git --no-pager <cmd>or-Pdisables it explicitly. - GUI editors must wait.
code,subland similar return immediately unless given a flag (code --wait,subl -w); otherwise Git sees an empty file and aborts. - Ask Git what it will use:
git var GIT_EDITORandgit var GIT_PAGERprint the resolved command, which is the quickest way to debug a surprise editor. - Per-command pager settings:
pager.<command>in configuration turns paging on or off for one subcommand, for examplegit config pager.branch false. git rebase -ireadsGIT_SEQUENCE_EDITORorsequence.editorfirst, which lets tools rewrite the todo list while leaving the commit-message editor alone.