Setup and Config
Getting and Creating Projects
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- All guides...
- 2.29.1 → 2.31.1 no changes
- 2.29.0 10/19/20
- 2.27.1 → 2.28.1 no changes
- 2.27.0 06/01/20
- 2.26.1 → 2.26.3 no changes
- 2.26.0 03/22/20
- 2.25.3 → 2.25.5 no changes
- 2.25.2 03/17/20
- 2.25.1 no changes
- 2.25.0 01/13/20
- 2.19.3 → 2.24.4 no changes
- 2.19.2 11/21/18
- 2.14.6 → 2.19.1 no changes
- 2.13.7 05/22/18
- 2.10.5 → 2.12.5 no changes
- 2.9.5 07/30/17
- 2.5.6 → 2.8.6 no changes
- 2.4.12 05/05/17
git config credential.https://example.com.username myusername git config credential.helper "$helper $options"
Git will sometimes need credentials from the user in order to perform operations; for example, it may need to ask for a username and password in order to access a remote repository over HTTP. This manual describes the mechanisms Git uses to request these credentials, as well as some features to avoid inputting these credentials repeatedly.
Without any credential helpers defined, Git will try the following strategies to ask the user for usernames and passwords:
GIT_ASKPASSenvironment variable is set, the program specified by the variable is invoked. A suitable prompt is provided to the program on the command line, and the user’s input is read from its standard output.
Otherwise, if the
core.askPassconfiguration variable is set, its value is used as above.
Otherwise, if the
SSH_ASKPASSenvironment variable is set, its value is used as above.
Otherwise, the user is prompted on the terminal.
It can be cumbersome to input the same credentials over and over. Git provides two methods to reduce this annoyance:
Static configuration of usernames for a given authentication context.
Credential helpers to cache or store passwords, or to interact with a system password wallet or keychain.
The first is simple and appropriate if you do not have secure storage available for a password. It is generally configured by adding this to your config:
[credential "https://example.com"] username = me
Credential helpers, on the other hand, are external programs from which Git can request both usernames and passwords; they typically interface with secure storage provided by the OS or other programs.
To use a helper, you must first select one to use. Git currently includes the following helpers:
You may also have third-party helpers installed; search for
credential-* in the output of
git help -a, and consult the
documentation of individual helpers. Once you have selected a helper,
you can tell Git to use it by putting its name into the
Find a helper.
$ git help -a | grep credential- credential-foo
Read its description.
$ git help credential-foo
Tell Git to use it.
$ git config --global credential.helper foo
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
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.
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
The following options are available in either location:
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. The resulting string is executed by the shell (so, for example, setting this to
foo --option=barwill execute
git credential-foo --option=barvia the shell. See the manual of specific helpers for examples of their use.
If there are multiple instances of the
credential.helperconfiguration variable, each helper will be tried in turn, and may provide a username, password, or nothing. Once Git has acquired both a username and a password, no more helpers will be tried.
credential.helperis configured to the empty string, this resets the helper list to empty (so you may override a helper set by a lower-priority config file by configuring the empty-string helper, followed by whatever set of helpers you would like).
A default username, if one is not provided in the URL.
By default, Git does not consider the "path" component of an http URL to be worth matching via external helpers. This means that a credential stored for
https://example.com/foo.gitwill also be used for
https://example.com/bar.git. If you do want to distinguish these cases, set this option to
You can write your own custom helpers to interface with any system in which you keep credentials. See the documentation for Git’s credentials API for details.
Part of the git suite