Home Explore Blog CI



git

4th chunk of `Documentation/gitcredentials.adoc`
7d8e8c6c2d725ff9ba475df8cadf3ca48303c2cc1990080f0000000100000872
 programs executed by Git to fetch or save
credentials from and to long-term storage (where "long-term" is simply
longer than a single Git process; e.g., credentials may be stored
in-memory for a few minutes, or indefinitely on disk).

Each helper is specified by a single string in the configuration
variable `credential.helper` (and others, see linkgit:git-config[1]).
The string is transformed by Git into a command to be executed using
these rules:

  1. If the helper string begins with "!", it is considered a shell
     snippet, and everything after the "!" becomes the command.

  2. Otherwise, if the helper string begins with an absolute path, the
     verbatim helper string becomes the command.

  3. Otherwise, the string "git credential-" is prepended to the helper
     string, and the result becomes the command.

The resulting command then has an "operation" argument appended to it
(see below for details), and the result is executed by the shell.

Here are some example specifications:

----------------------------------------------------
# run "git credential-foo"
[credential]
	helper = foo

# same as above, but pass an argument to the helper
[credential]
	helper = "foo --bar=baz"

# the arguments are parsed by the shell, so use shell
# quoting if necessary
[credential]
	helper = "foo --bar='whitespace arg'"

# store helper (discouraged) with custom location for the db file;
# use `--file ~/.git-secret.txt`, rather than `--file=~/.git-secret.txt`,
# to allow the shell to expand tilde to the home directory.
[credential]
	helper = "store --file ~/.git-secret.txt"

# you can also use an absolute path, which will not use the git wrapper
[credential]
	helper = "/path/to/my/helper --with-arguments"

# or you can specify your own shell snippet
[credential "https://example.com"]
	username = your_user
	helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
----------------------------------------------------

Generally speaking, rule (3) above is the simplest for users to specify.
Authors of credential helpers should make an effort to assist their
users by naming their program "git-credential-$NAME",

Title: Specifying and Configuring Git Credential Helpers
Summary
This section describes how to specify and configure Git credential helpers, including the rules for transforming helper strings into executable commands, and provides examples of different helper specifications, such as using absolute paths, shell snippets, and custom helper programs.