Home Explore Blog CI



git

2nd chunk of `Documentation/gitcredentials.adoc`
efb078e569a7098ea75403275338f9736e09af73158991530000000100000fa4

-------------------------------------------
$ git config --global credential.helper foo
-------------------------------------------

=== Available helpers

Git currently includes the following helpers:

cache::

    Cache credentials in memory for a short period of time. See
    linkgit:git-credential-cache[1] for details.

store::

    Store credentials indefinitely on disk. See
    linkgit:git-credential-store[1] for details.

Popular helpers with secure persistent storage include:

    - git-credential-libsecret (Linux)

    - git-credential-osxkeychain (macOS)

    - git-credential-wincred (Windows)

    - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)

The community maintains a comprehensive list of Git credential helpers at
https://git-scm.com/doc/credential-helpers.

=== OAuth

An alternative to inputting passwords or personal access tokens is to use an
OAuth credential helper. Initial authentication opens a browser window to the
host. Subsequent authentication happens in the background. Many popular Git
hosts support OAuth.

Popular helpers with OAuth support include:

    - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)

    - https://github.com/hickford/git-credential-oauth[git-credential-oauth] (cross platform, included in many Linux distributions)

    - https://github.com/AdityaGarg8/git-credential-email[git-credential-gmail] (cross platform, dedicated helper to authenticate Gmail accounts for linkgit:git-send-email[1])

    - https://github.com/AdityaGarg8/git-credential-email[git-credential-outlook] (cross platform, dedicated helper to authenticate Microsoft Outlook accounts for linkgit:git-send-email[1])

CREDENTIAL CONTEXTS
-------------------

Git considers each credential to have a context defined by a URL. This context
is used to look up context-specific configuration, and is passed to any
helpers, which may use it as an index into secure storage.

For instance, imagine we are accessing `https://example.com/foo.git`. When Git
looks into a config file to see if a section matches this context, it will
consider the two a match if the context is a more-specific subset of the
pattern in the config file. For example, if you have this in your config file:

--------------------------------------
[credential "https://example.com"]
	username = foo
--------------------------------------

then we will match: both protocols are the same, both hosts are the same, and
the "pattern" URL does not care about the path component at all. However, this
context would not match:

--------------------------------------
[credential "https://kernel.org"]
	username = foo
--------------------------------------

because the hostnames differ. Nor would it match `foo.example.com`; Git
compares hostnames exactly, without considering whether two hosts are part of
the same domain. Likewise, a config entry for `http://example.com` would not
match: Git compares the protocols exactly.  However, you may use wildcards in
the domain name and other pattern matching techniques as with the `http.<URL>.*`
options.

If the "pattern" URL does include a path component, then this too must match
exactly: the context `https://example.com/bar/baz.git` will match a config
entry for `https://example.com/bar/baz.git` (in addition to matching the config
entry for `https://example.com`) but will not match a config entry for
`https://example.com/bar`.


CONFIGURATION OPTIONS
---------------------

Options for a credential context can be configured either in
`credential.*` (which applies to all credentials), or
`credential.<URL>.*`, where <URL> matches the context as described
above.

The following options are available in either location:

helper::

	The name of an external credential helper, and any associated options.
	If the helper name is not an absolute path, then the string `git
	credential-` is prepended.

Title: Git Credential Helpers and Configuration
Summary
This section describes the available Git credential helpers, including those with secure persistent storage and OAuth support, as well as how to configure credential contexts using URL patterns and options, allowing for customized and secure credential management in Git.