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.
git var <variable> git var -l
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 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.useConfigOnlyis 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_PAGERand config passed throughGIT_CONFIG_COUNT/-cbeat files, so a value you set withgit configmay seem to be ignored. The examples above clear them first. - Several candidates.
GIT_CONFIG_GLOBALandGIT_ATTR_GLOBALcan print more than one line, one for each location Git consults (~/.gitconfigand the XDG path). - Using it in scripts.
editor=$(git var GIT_EDITOR)followed byeval "$editor" filehonors 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. -lmixes two lists. Everything before theGIT_lines is ordinary configuration (likegit config --list); do not depend on the order.- Not the same as
git config.git config user.namereports what is set in configuration;git var GIT_AUTHOR_IDENTalso 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_BRANCHwas added in Git 2.28 together withinit.defaultBranch.GIT_CONFIG_SYSTEMis left out whenGIT_CONFIG_NOSYSTEMis set.
Related
- git config, git commit, git help
- Lessons: Setup and Configuration