Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
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

Bash Scripted editor: write the message from a program

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.

Bash Editor precedence and a todo-list editor

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

Terminal
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 -m for messages, or GIT_EDITOR=true to accept whatever Git pre-filled (true exits 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 | head and CI logs are already unpaged. git --no-pager <cmd> or -P disables it explicitly.
  • GUI editors must wait. code, subl and 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_EDITOR and git var GIT_PAGER print 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 example git config pager.branch false.
  • git rebase -i reads GIT_SEQUENCE_EDITOR or sequence.editor first, which lets tools rewrite the todo list while leaving the commit-message editor alone.