Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Setup and Basics

git var command

Reference for git var: print the identity, editor, pager, default branch and other logical variables Git would use, exactly as Git resolves them.

git var prints a "logical variable": a value that Git works out by combining environment variables, configuration and built-in defaults. Instead of guessing which editor Git would open or what name goes on the next commit, you ask Git and get the answer it would use.

This is mostly useful in scripts and tools that want to behave like Git, for example a commit helper that needs the author line, or a hook that wants to launch the user's editor.

Terminal
git var <variable>
git var -l

Try it

Bash Identity, editor and default branch

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 Listing everything and unknown names

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 var ( -l | <variable> )
Variable What it prints
GIT_AUTHOR_IDENT Name <email> timestamp timezone for the next commit's author, from GIT_AUTHOR_NAME/_EMAIL/_DATE or user.*.
GIT_COMMITTER_IDENT The same for the committer.
GIT_EDITOR The editor command: $GIT_EDITOR, then core.editor, then $VISUAL, then $EDITOR, then the compiled default (vi).
GIT_SEQUENCE_EDITOR The editor for the rebase todo list: $GIT_SEQUENCE_EDITOR, sequence.editor, then GIT_EDITOR.
GIT_PAGER The pager: $GIT_PAGER, core.pager, $PAGER, then less.
GIT_DEFAULT_BRANCH The initial branch name for new repositories (init.defaultBranch, otherwise master).
GIT_SHELL_PATH The shell Git uses to run scripts and hooks.
GIT_ATTR_SYSTEM, GIT_ATTR_GLOBAL Paths of the system and user attributes files.
GIT_CONFIG_SYSTEM, GIT_CONFIG_GLOBAL Paths of the system and user configuration files.
-l Prints all configuration variables as key=value followed by all logical variables.

Errors: an unknown name prints the usage line and exits with status 129. Asking for an identity when none can be worked out fails with fatal: unable to auto-detect email address, unless the identity is given in an environment variable or configuration. A variable that is not set to anything meaningful, such as GIT_PAGER when you run it without a terminal, may print an empty line.

Usage notes

  • Identity needs a name and email. If user.useConfigOnly is true, Git refuses to guess from the system user name and hostname; this prevents commits with throwaway addresses like [email protected].
  • The timestamp in an identity line is Unix seconds plus a time zone offset, for instance 1767261600 +0000. That is the same format stored inside commit objects.
  • Environment wins. GIT_EDITOR, GIT_PAGER and config passed through GIT_CONFIG_COUNT/-c beat files, so a value you set with git config may seem to be ignored. The examples above clear them first.
  • Several candidates. GIT_CONFIG_GLOBAL and GIT_ATTR_GLOBAL can print more than one line, one for each location Git consults (~/.gitconfig and the XDG path).
  • Using it in scripts. editor=$(git var GIT_EDITOR) followed by eval "$editor" file honors the user's choice including arguments. The value can contain options and quoting, so run it through a shell, never as a single executable name.
  • -l mixes two lists. Everything before the GIT_ lines is ordinary configuration (like git config --list); do not depend on the order.
  • Not the same as git config. git config user.name reports what is set in configuration; git var GIT_AUTHOR_IDENT also honors environment variables and fallbacks.
  • Edge: environment variables with an empty value count as set in some cases, so check the output rather than assuming a fallback was used.
  • Versions. GIT_DEFAULT_BRANCH was added in Git 2.28 together with init.defaultBranch. GIT_CONFIG_SYSTEM is left out when GIT_CONFIG_NOSYSTEM is set.