LinuxCommandLibrary

git-var

Show git internal variable

TLDR

Print the value of a Git logical variable

$ git var [GIT_AUTHOR_IDENT|GIT_COMMITTER_IDENT|GIT_EDITOR|GIT_PAGER]
copy

[l]ist all Git logical variables
$ git var -l
copy

SYNOPSIS

git var <variable>

PARAMETERS

<variable>
    The name of the logical Git variable to query. Supported variables include: GIT_AUTHOR_IDENT, GIT_COMMITTER_IDENT, GIT_EDITOR, GIT_PAGER, GIT_SSH_COMMAND, GIT_EXEC_PATH, GIT_PREFIX, and GIT_INTERNAL_TEST_DRIVER.

DESCRIPTION

The git-var command is a low-level "plumbing" utility designed to query specific logical variables that Git maintains or utilizes internally. Unlike git config, which reads arbitrary configuration values, git-var focuses on a predefined set of variables crucial to Git's operational context, often related to user identification, internal paths, or the execution of external programs.

These variables include: GIT_AUTHOR_IDENT and GIT_COMMITTER_IDENT (which provide formatted author and committer identities), GIT_EDITOR and GIT_PAGER (determining the editor for interactive prompts and the pager for output display), GIT_SSH_COMMAND (for SSH operations), and GIT_EXEC_PATH (the absolute path where Git looks for its subcommands and helper programs). It also queries GIT_PREFIX, which represents the relative path from the current working directory to the top-level directory of the Git working tree.

This command is primarily intended for scripting purposes, allowing external scripts and Git's own internal mechanisms to reliably retrieve consistent information about its operating environment and state without needing to parse complex configuration files or outputs of other commands.

CAVEATS

git-var is categorized as a "plumbing" command, indicating it's a low-level interface primarily for scripting and internal Git operations, not typically for direct end-user interaction. It queries a specific, limited set of internal Git variables and should not be confused with git config, which is used for reading and writing general Git configuration options.

VARIABLE TYPES AND THEIR MEANING

  • GIT_AUTHOR_IDENT and GIT_COMMITTER_IDENT: These variables output a formatted identity string (e.g., 'Name <email> Timestamp ±Timezone') derived from the user.name, user.email, and user.date configuration settings.
  • GIT_EDITOR, GIT_PAGER, GIT_SSH_COMMAND: These variables return the determined paths or commands for external tools, as established by Git's configuration and environment variables.
  • GIT_EXEC_PATH: Provides the absolute path where Git expects to find its helper programs and subcommands. This is crucial for Git's internal operation.
  • GIT_PREFIX: Outputs the relative path from the current working directory to the top-level directory of the Git working tree. This is particularly useful when executing Git commands from a subdirectory within a repository.
  • GIT_INTERNAL_TEST_DRIVER: A variable primarily used for internal Git testing purposes and not typically relevant for general usage.

HISTORY

git-var has been a stable part of Git's plumbing commands for a significant period, serving its specific purpose of querying essential internal variables. Its functionality has remained largely consistent, focusing on providing reliable access to key operational parameters and identities for scripting and Git's internal processes. It was introduced to standardize how Git's own scripts and external tools could consistently determine certain crucial environmental and identity-related information.

SEE ALSO

Copied to clipboard