6 gitcredentials - Providing usernames and passwords to Git
11 git config credential.https://example.com.username myusername
12 git config credential.helper "$helper $options"
18 Git will sometimes need credentials from the user in order to perform
19 operations; for example, it may need to ask for a username and password
20 in order to access a remote repository over HTTP. Some remotes accept
21 a personal access token or OAuth access token as a password. This
22 manual describes the mechanisms Git uses to request these credentials,
23 as well as some features to avoid inputting these credentials repeatedly.
25 REQUESTING CREDENTIALS
26 ----------------------
28 Without any credential helpers defined, Git will try the following
29 strategies to ask the user for usernames and passwords:
31 1. If the `GIT_ASKPASS` environment variable is set, the program
32 specified by the variable is invoked. A suitable prompt is provided
33 to the program on the command line, and the user's input is read
34 from its standard output.
36 2. Otherwise, if the `core.askPass` configuration variable is set, its
37 value is used as above.
39 3. Otherwise, if the `SSH_ASKPASS` environment variable is set, its
40 value is used as above.
42 4. Otherwise, the user is prompted on the terminal.
47 It can be cumbersome to input the same credentials over and over. Git
48 provides two methods to reduce this annoyance:
50 1. Static configuration of usernames for a given authentication context.
52 2. Credential helpers to cache or store passwords, or to interact with
53 a system password wallet or keychain.
55 The first is simple and appropriate if you do not have secure storage available
56 for a password. It is generally configured by adding this to your config:
58 ---------------------------------------
59 [credential "https://example.com"]
61 ---------------------------------------
63 Credential helpers, on the other hand, are external programs from which Git can
64 request both usernames and passwords; they typically interface with secure
65 storage provided by the OS or other programs. Alternatively, a
66 credential-generating helper might generate credentials for certain servers via
69 To use a helper, you must first select one to use (see below for a list).
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.
79 -------------------------------------------
80 $ git help -a | grep credential-
82 -------------------------------------------
84 2. Read its description.
86 -------------------------------------------
87 $ git help credential-foo
88 -------------------------------------------
90 3. Tell Git to use it.
92 -------------------------------------------
93 $ git config --global credential.helper foo
94 -------------------------------------------
98 Git currently includes the following helpers:
102 Cache credentials in memory for a short period of time. See
103 linkgit:git-credential-cache[1] for details.
107 Store credentials indefinitely on disk. See
108 linkgit:git-credential-store[1] for details.
110 Popular helpers with secure persistent storage include:
112 - git-credential-libsecret (Linux)
114 - git-credential-osxkeychain (macOS)
116 - git-credential-wincred (Windows)
118 - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
120 The community maintains a comprehensive list of Git credential helpers at
121 https://git-scm.com/doc/credential-helpers.
125 An alternative to inputting passwords or personal access tokens is to use an
126 OAuth credential helper. Initial authentication opens a browser window to the
127 host. Subsequent authentication happens in the background. Many popular Git
130 Popular helpers with OAuth support include:
132 - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
134 - https://github.com/hickford/git-credential-oauth[git-credential-oauth] (cross platform, included in many Linux distributions)
139 Git considers each credential to have a context defined by a URL. This context
140 is used to look up context-specific configuration, and is passed to any
141 helpers, which may use it as an index into secure storage.
143 For instance, imagine we are accessing `https://example.com/foo.git`. When Git
144 looks into a config file to see if a section matches this context, it will
145 consider the two a match if the context is a more-specific subset of the
146 pattern in the config file. For example, if you have this in your config file:
148 --------------------------------------
149 [credential "https://example.com"]
151 --------------------------------------
153 then we will match: both protocols are the same, both hosts are the same, and
154 the "pattern" URL does not care about the path component at all. However, this
155 context would not match:
157 --------------------------------------
158 [credential "https://kernel.org"]
160 --------------------------------------
162 because the hostnames differ. Nor would it match `foo.example.com`; Git
163 compares hostnames exactly, without considering whether two hosts are part of
164 the same domain. Likewise, a config entry for `http://example.com` would not
165 match: Git compares the protocols exactly. However, you may use wildcards in
166 the domain name and other pattern matching techniques as with the `http.<URL>.*`
169 If the "pattern" URL does include a path component, then this too must match
170 exactly: the context `https://example.com/bar/baz.git` will match a config
171 entry for `https://example.com/bar/baz.git` (in addition to matching the config
172 entry for `https://example.com`) but will not match a config entry for
173 `https://example.com/bar`.
176 CONFIGURATION OPTIONS
177 ---------------------
179 Options for a credential context can be configured either in
180 `credential.*` (which applies to all credentials), or
181 `credential.<URL>.*`, where <URL> matches the context as described
184 The following options are available in either location:
188 The name of an external credential helper, and any associated options.
189 If the helper name is not an absolute path, then the string `git
190 credential-` is prepended. The resulting string is executed by the
191 shell (so, for example, setting this to `foo --option=bar` will execute
192 `git credential-foo --option=bar` via the shell. See the manual of
193 specific helpers for examples of their use.
195 If there are multiple instances of the `credential.helper` configuration
196 variable, each helper will be tried in turn, and may provide a username,
197 password, or nothing. Once Git has acquired both a username and a
198 non-expired password, no more helpers will be tried.
200 If `credential.helper` is configured to the empty string, this resets
201 the helper list to empty (so you may override a helper set by a
202 lower-priority config file by configuring the empty-string helper,
203 followed by whatever set of helpers you would like).
207 A default username, if one is not provided in the URL.
211 By default, Git does not consider the "path" component of an http URL
212 to be worth matching via external helpers. This means that a credential
213 stored for `https://example.com/foo.git` will also be used for
214 `https://example.com/bar.git`. If you do want to distinguish these
215 cases, set this option to `true`.
221 You can write your own custom helpers to interface with any system in
222 which you keep credentials.
224 Credential helpers are programs executed by Git to fetch or save
225 credentials from and to long-term storage (where "long-term" is simply
226 longer than a single Git process; e.g., credentials may be stored
227 in-memory for a few minutes, or indefinitely on disk).
229 Each helper is specified by a single string in the configuration
230 variable `credential.helper` (and others, see linkgit:git-config[1]).
231 The string is transformed by Git into a command to be executed using
234 1. If the helper string begins with "!", it is considered a shell
235 snippet, and everything after the "!" becomes the command.
237 2. Otherwise, if the helper string begins with an absolute path, the
238 verbatim helper string becomes the command.
240 3. Otherwise, the string "git credential-" is prepended to the helper
241 string, and the result becomes the command.
243 The resulting command then has an "operation" argument appended to it
244 (see below for details), and the result is executed by the shell.
246 Here are some example specifications:
248 ----------------------------------------------------
249 # run "git credential-foo"
253 # same as above, but pass an argument to the helper
255 helper = "foo --bar=baz"
257 # the arguments are parsed by the shell, so use shell
258 # quoting if necessary
260 helper = "foo --bar='whitespace arg'"
262 # store helper (discouraged) with custom location for the db file;
263 # use `--file ~/.git-secret.txt`, rather than `--file=~/.git-secret.txt`,
264 # to allow the shell to expand tilde to the home directory.
266 helper = "store --file ~/.git-secret.txt"
268 # you can also use an absolute path, which will not use the git wrapper
270 helper = "/path/to/my/helper --with-arguments"
272 # or you can specify your own shell snippet
273 [credential "https://example.com"]
275 helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
276 ----------------------------------------------------
278 Generally speaking, rule (3) above is the simplest for users to specify.
279 Authors of credential helpers should make an effort to assist their
280 users by naming their program "git-credential-$NAME", and putting it in
281 the `$PATH` or `$GIT_EXEC_PATH` during installation, which will allow a
282 user to enable it with `git config credential.helper $NAME`.
284 When a helper is executed, it will have one "operation" argument
285 appended to its command line, which is one of:
289 Return a matching credential, if any exists.
293 Store the credential, if applicable to the helper.
297 Remove matching credentials, if any, from the helper's storage.
299 The details of the credential will be provided on the helper's stdin
300 stream. The exact format is the same as the input/output format of the
301 `git credential` plumbing command (see the section `INPUT/OUTPUT
302 FORMAT` in linkgit:git-credential[1] for a detailed specification).
304 For a `get` operation, the helper should produce a list of attributes on
305 stdout in the same format (see linkgit:git-credential[1] for common
306 attributes). A helper is free to produce a subset, or even no values at
307 all if it has nothing useful to provide. Any provided attributes will
308 overwrite those already known about by Git's credential subsystem.
309 Unrecognised attributes are silently discarded.
311 While it is possible to override all attributes, well behaving helpers
312 should refrain from doing so for any attribute other than username and
315 If a helper outputs a `quit` attribute with a value of `true` or `1`,
316 no further helpers will be consulted, nor will the user be prompted
317 (if no credential has been provided, the operation will then fail).
319 Similarly, no more helpers will be consulted once both username and
320 password had been provided.
322 For a `store` or `erase` operation, the helper's output is ignored.
324 If a helper fails to perform the requested operation or needs to notify
325 the user of a potential issue, it may write to stderr.
327 If it does not support the requested operation (e.g., a read-only store
328 or generator), it should silently ignore the request.
330 If a helper receives any other operation, it should silently ignore the
331 request. This leaves room for future operations to be added (older
332 helpers will just ignore the new requests).
336 Part of the linkgit:git[1] suite