1GITCREDENTIALS(7)                 Git Manual                 GITCREDENTIALS(7)
2
3
4

NAME

6       gitcredentials - Providing usernames and passwords to Git
7

SYNOPSIS

9       git config credential.https://example.com.username myusername
10       git config credential.helper "$helper $options"
11

DESCRIPTION

13       Git will sometimes need credentials from the user in order to perform
14       operations; for example, it may need to ask for a username and password
15       in order to access a remote repository over HTTP. Some remotes accept a
16       personal access token or OAuth access token as a password. This manual
17       describes the mechanisms Git uses to request these credentials, as well
18       as some features to avoid inputting these credentials repeatedly.
19

REQUESTING CREDENTIALS

21       Without any credential helpers defined, Git will try the following
22       strategies to ask the user for usernames and passwords:
23
24        1. If the GIT_ASKPASS environment variable is set, the program
25           specified by the variable is invoked. A suitable prompt is provided
26           to the program on the command line, and the user’s input is read
27           from its standard output.
28
29        2. Otherwise, if the core.askPass configuration variable is set, its
30           value is used as above.
31
32        3. Otherwise, if the SSH_ASKPASS environment variable is set, its
33           value is used as above.
34
35        4. Otherwise, the user is prompted on the terminal.
36

AVOIDING REPETITION

38       It can be cumbersome to input the same credentials over and over. Git
39       provides two methods to reduce this annoyance:
40
41        1. Static configuration of usernames for a given authentication
42           context.
43
44        2. Credential helpers to cache or store passwords, or to interact with
45           a system password wallet or keychain.
46
47       The first is simple and appropriate if you do not have secure storage
48       available for a password. It is generally configured by adding this to
49       your config:
50
51           [credential "https://example.com"]
52                   username = me
53
54       Credential helpers, on the other hand, are external programs from which
55       Git can request both usernames and passwords; they typically interface
56       with secure storage provided by the OS or other programs.
57       Alternatively, a credential-generating helper might generate
58       credentials for certain servers via some API.
59
60       To use a helper, you must first select one to use. Git currently
61       includes the following helpers:
62
63       cache
64           Cache credentials in memory for a short period of time. See git-
65           credential-cache(1) for details.
66
67       store
68           Store credentials indefinitely on disk. See git-credential-store(1)
69           for details.
70
71       You may also have third-party helpers installed; search for
72       credential-* in the output of git help -a, and consult the
73       documentation of individual helpers. Once you have selected a helper,
74       you can tell Git to use it by putting its name into the
75       credential.helper variable.
76
77        1. Find a helper.
78
79               $ git help -a | grep credential-
80               credential-foo
81
82        2. Read its description.
83
84               $ git help credential-foo
85
86        3. Tell Git to use it.
87
88               $ git config --global credential.helper foo
89

CREDENTIAL CONTEXTS

91       Git considers each credential to have a context defined by a URL. This
92       context is used to look up context-specific configuration, and is
93       passed to any helpers, which may use it as an index into secure
94       storage.
95
96       For instance, imagine we are accessing https://example.com/foo.git.
97       When Git looks into a config file to see if a section matches this
98       context, it will consider the two a match if the context is a
99       more-specific subset of the pattern in the config file. For example, if
100       you have this in your config file:
101
102           [credential "https://example.com"]
103                   username = foo
104
105       then we will match: both protocols are the same, both hosts are the
106       same, and the "pattern" URL does not care about the path component at
107       all. However, this context would not match:
108
109           [credential "https://kernel.org"]
110                   username = foo
111
112       because the hostnames differ. Nor would it match foo.example.com; Git
113       compares hostnames exactly, without considering whether two hosts are
114       part of the same domain. Likewise, a config entry for
115       http://example.com would not match: Git compares the protocols exactly.
116       However, you may use wildcards in the domain name and other pattern
117       matching techniques as with the http.<URL>.* options.
118
119       If the "pattern" URL does include a path component, then this too must
120       match exactly: the context https://example.com/bar/baz.git will match a
121       config entry for https://example.com/bar/baz.git (in addition to
122       matching the config entry for https://example.com) but will not match a
123       config entry for https://example.com/bar.
124

CONFIGURATION OPTIONS

126       Options for a credential context can be configured either in
127       credential.* (which applies to all credentials), or credential.<URL>.*,
128       where <URL> matches the context as described above.
129
130       The following options are available in either location:
131
132       helper
133           The name of an external credential helper, and any associated
134           options. If the helper name is not an absolute path, then the
135           string git credential- is prepended. The resulting string is
136           executed by the shell (so, for example, setting this to foo
137           --option=bar will execute git credential-foo --option=bar via the
138           shell. See the manual of specific helpers for examples of their
139           use.
140
141           If there are multiple instances of the credential.helper
142           configuration variable, each helper will be tried in turn, and may
143           provide a username, password, or nothing. Once Git has acquired
144           both a username and a password, no more helpers will be tried.
145
146           If credential.helper is configured to the empty string, this resets
147           the helper list to empty (so you may override a helper set by a
148           lower-priority config file by configuring the empty-string helper,
149           followed by whatever set of helpers you would like).
150
151       username
152           A default username, if one is not provided in the URL.
153
154       useHttpPath
155           By default, Git does not consider the "path" component of an http
156           URL to be worth matching via external helpers. This means that a
157           credential stored for https://example.com/foo.git will also be used
158           for https://example.com/bar.git. If you do want to distinguish
159           these cases, set this option to true.
160

CUSTOM HELPERS

162       You can write your own custom helpers to interface with any system in
163       which you keep credentials.
164
165       Credential helpers are programs executed by Git to fetch or save
166       credentials from and to long-term storage (where "long-term" is simply
167       longer than a single Git process; e.g., credentials may be stored
168       in-memory for a few minutes, or indefinitely on disk).
169
170       Each helper is specified by a single string in the configuration
171       variable credential.helper (and others, see git-config(1)). The string
172       is transformed by Git into a command to be executed using these rules:
173
174        1. If the helper string begins with "!", it is considered a shell
175           snippet, and everything after the "!" becomes the command.
176
177        2. Otherwise, if the helper string begins with an absolute path, the
178           verbatim helper string becomes the command.
179
180        3. Otherwise, the string "git credential-" is prepended to the helper
181           string, and the result becomes the command.
182
183       The resulting command then has an "operation" argument appended to it
184       (see below for details), and the result is executed by the shell.
185
186       Here are some example specifications:
187
188           # run "git credential-foo"
189           [credential]
190                   helper = foo
191
192           # same as above, but pass an argument to the helper
193           [credential]
194                   helper = "foo --bar=baz"
195
196           # the arguments are parsed by the shell, so use shell
197           # quoting if necessary
198           [credential]
199                   helper = "foo --bar='whitespace arg'"
200
201           # you can also use an absolute path, which will not use the git wrapper
202           [credential]
203                   helper = "/path/to/my/helper --with-arguments"
204
205           # or you can specify your own shell snippet
206           [credential "https://example.com"]
207                   username = your_user
208                   helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
209
210       Generally speaking, rule (3) above is the simplest for users to
211       specify. Authors of credential helpers should make an effort to assist
212       their users by naming their program "git-credential-$NAME", and putting
213       it in the $PATH or $GIT_EXEC_PATH during installation, which will allow
214       a user to enable it with git config credential.helper $NAME.
215
216       When a helper is executed, it will have one "operation" argument
217       appended to its command line, which is one of:
218
219       get
220           Return a matching credential, if any exists.
221
222       store
223           Store the credential, if applicable to the helper.
224
225       erase
226           Remove a matching credential, if any, from the helper’s storage.
227
228       The details of the credential will be provided on the helper’s stdin
229       stream. The exact format is the same as the input/output format of the
230       git credential plumbing command (see the section INPUT/OUTPUT FORMAT in
231       git-credential(1) for a detailed specification).
232
233       For a get operation, the helper should produce a list of attributes on
234       stdout in the same format (see git-credential(1) for common
235       attributes). A helper is free to produce a subset, or even no values at
236       all if it has nothing useful to provide. Any provided attributes will
237       overwrite those already known about by Git’s credential subsystem.
238       Unrecognised attributes are silently discarded.
239
240       While it is possible to override all attributes, well behaving helpers
241       should refrain from doing so for any attribute other than username and
242       password.
243
244       If a helper outputs a quit attribute with a value of true or 1, no
245       further helpers will be consulted, nor will the user be prompted (if no
246       credential has been provided, the operation will then fail).
247
248       Similarly, no more helpers will be consulted once both username and
249       password had been provided.
250
251       For a store or erase operation, the helper’s output is ignored.
252
253       If a helper fails to perform the requested operation or needs to notify
254       the user of a potential issue, it may write to stderr.
255
256       If it does not support the requested operation (e.g., a read-only store
257       or generator), it should silently ignore the request.
258
259       If a helper receives any other operation, it should silently ignore the
260       request. This leaves room for future operations to be added (older
261       helpers will just ignore the new requests).
262

GIT

264       Part of the git(1) suite
265
266
267
268Git 2.39.1                        2023-01-13                 GITCREDENTIALS(7)
Impressum