blob: 1814d2d23c189c9597205eb2c0ca7f3d0c2306c3 [file] [log] [blame]
Junio C Hamano0df92712011-12-21 22:30:441gitcredentials(7)
2=================
3
4NAME
5----
Junio C Hamano076ffcc2013-02-06 05:13:216gitcredentials - providing usernames and passwords to Git
Junio C Hamano0df92712011-12-21 22:30:447
8SYNOPSIS
9--------
10------------------
11git config credential.https://example.com.username myusername
12git config credential.helper "$helper $options"
13------------------
14
15DESCRIPTION
16-----------
17
18Git will sometimes need credentials from the user in order to perform
19operations; for example, it may need to ask for a username and password
20in order to access a remote repository over HTTP. This manual describes
Junio C Hamano076ffcc2013-02-06 05:13:2121the mechanisms Git uses to request these credentials, as well as some
Junio C Hamano0df92712011-12-21 22:30:4422features to avoid inputting these credentials repeatedly.
23
24REQUESTING CREDENTIALS
25----------------------
26
Junio C Hamano076ffcc2013-02-06 05:13:2127Without any credential helpers defined, Git will try the following
Junio C Hamano0df92712011-12-21 22:30:4428strategies to ask the user for usernames and passwords:
29
301. If the `GIT_ASKPASS` environment variable is set, the program
31 specified by the variable is invoked. A suitable prompt is provided
32 to the program on the command line, and the user's input is read
33 from its standard output.
34
Junio C Hamano322c6242015-03-23 21:32:46352. Otherwise, if the `core.askPass` configuration variable is set, its
Junio C Hamano0df92712011-12-21 22:30:4436 value is used as above.
37
383. Otherwise, if the `SSH_ASKPASS` environment variable is set, its
39 value is used as above.
40
414. Otherwise, the user is prompted on the terminal.
42
43AVOIDING REPETITION
44-------------------
45
46It can be cumbersome to input the same credentials over and over. Git
47provides two methods to reduce this annoyance:
48
491. Static configuration of usernames for a given authentication context.
50
512. Credential helpers to cache or store passwords, or to interact with
52 a system password wallet or keychain.
53
54The first is simple and appropriate if you do not have secure storage available
55for a password. It is generally configured by adding this to your config:
56
57---------------------------------------
58[credential "https://example.com"]
59username = me
60---------------------------------------
61
Junio C Hamano076ffcc2013-02-06 05:13:2162Credential helpers, on the other hand, are external programs from which Git can
Junio C Hamano0df92712011-12-21 22:30:4463request both usernames and passwords; they typically interface with secure
64storage provided by the OS or other programs.
65
66To use a helper, you must first select one to use. Git currently
67includes the following helpers:
68
69cache::
70
71Cache credentials in memory for a short period of time. See
72linkgit:git-credential-cache[1] for details.
73
74store::
75
76Store credentials indefinitely on disk. See
77linkgit:git-credential-store[1] for details.
78
79You may also have third-party helpers installed; search for
80`credential-*` in the output of `git help -a`, and consult the
81documentation of individual helpers. Once you have selected a helper,
Junio C Hamano076ffcc2013-02-06 05:13:2182you can tell Git to use it by putting its name into the
Junio C Hamano0df92712011-12-21 22:30:4483credential.helper variable.
84
851. Find a helper.
86+
87-------------------------------------------
88$ git help -a | grep credential-
89credential-foo
90-------------------------------------------
91
922. Read its description.
93+
94-------------------------------------------
95$ git help credential-foo
96-------------------------------------------
97
Junio C Hamano076ffcc2013-02-06 05:13:21983. Tell Git to use it.
Junio C Hamano0df92712011-12-21 22:30:4499+
100-------------------------------------------
101$ git config --global credential.helper foo
102-------------------------------------------
103
Junio C Hamano0df92712011-12-21 22:30:44104
105CREDENTIAL CONTEXTS
106-------------------
107
108Git considers each credential to have a context defined by a URL. This context
109is used to look up context-specific configuration, and is passed to any
110helpers, which may use it as an index into secure storage.
111
Junio C Hamano076ffcc2013-02-06 05:13:21112For instance, imagine we are accessing `https://example.com/foo.git`. When Git
Junio C Hamano0df92712011-12-21 22:30:44113looks into a config file to see if a section matches this context, it will
114consider the two a match if the context is a more-specific subset of the
115pattern in the config file. For example, if you have this in your config file:
116
117--------------------------------------
118[credential "https://example.com"]
119username = foo
120--------------------------------------
121
122then we will match: both protocols are the same, both hosts are the same, and
123the "pattern" URL does not care about the path component at all. However, this
124context would not match:
125
126--------------------------------------
127[credential "https://kernel.org"]
128username = foo
129--------------------------------------
130
Junio C Hamano076ffcc2013-02-06 05:13:21131because the hostnames differ. Nor would it match `foo.example.com`; Git
Junio C Hamano0df92712011-12-21 22:30:44132compares hostnames exactly, without considering whether two hosts are part of
133the same domain. Likewise, a config entry for `http://example.com` would not
Junio C Hamanob082a532020-03-05 21:52:25134match: Git compares the protocols exactly. However, you may use wildcards in
135the domain name and other pattern matching techniques as with the `http.<url>.*`
136options.
Junio C Hamano0df92712011-12-21 22:30:44137
Junio C Hamano32a75272018-10-16 07:37:35138If the "pattern" URL does include a path component, then this too must match
139exactly: the context `https://example.com/bar/baz.git` will match a config
140entry for `https://example.com/bar/baz.git` (in addition to matching the config
141entry for `https://example.com`) but will not match a config entry for
142`https://example.com/bar`.
143
Junio C Hamano0df92712011-12-21 22:30:44144
145CONFIGURATION OPTIONS
146---------------------
147
148Options for a credential context can be configured either in
Junio C Hamanob76a6862012-05-02 22:02:46149`credential.*` (which applies to all credentials), or
150`credential.<url>.*`, where <url> matches the context as described
Junio C Hamano0df92712011-12-21 22:30:44151above.
152
153The following options are available in either location:
154
155helper::
156
157The name of an external credential helper, and any associated options.
158If the helper name is not an absolute path, then the string `git
159credential-` is prepended. The resulting string is executed by the
160shell (so, for example, setting this to `foo --option=bar` will execute
161`git credential-foo --option=bar` via the shell. See the manual of
162specific helpers for examples of their use.
Junio C Hamanod5176902017-05-16 04:30:56163+
164If there are multiple instances of the `credential.helper` configuration
165variable, each helper will be tried in turn, and may provide a username,
166password, or nothing. Once Git has acquired both a username and a
167password, no more helpers will be tried.
168+
169If `credential.helper` is configured to the empty string, this resets
170the helper list to empty (so you may override a helper set by a
171lower-priority config file by configuring the empty-string helper,
172followed by whatever set of helpers you would like).
Junio C Hamano0df92712011-12-21 22:30:44173
174username::
175
176A default username, if one is not provided in the URL.
177
178useHttpPath::
179
Junio C Hamano076ffcc2013-02-06 05:13:21180By default, Git does not consider the "path" component of an http URL
Junio C Hamano0df92712011-12-21 22:30:44181to be worth matching via external helpers. This means that a credential
182stored for `https://example.com/foo.git` will also be used for
183`https://example.com/bar.git`. If you do want to distinguish these
184cases, set this option to `true`.
185
186
187CUSTOM HELPERS
188--------------
189
190You can write your own custom helpers to interface with any system in
Junio C Hamano5b8e1232020-02-17 22:05:06191which you keep credentials.
192
193Credential helpers are programs executed by Git to fetch or save
194credentials from and to long-term storage (where "long-term" is simply
195longer than a single Git process; e.g., credentials may be stored
196in-memory for a few minutes, or indefinitely on disk).
197
198Each helper is specified by a single string in the configuration
199variable `credential.helper` (and others, see linkgit:git-config[1]).
200The string is transformed by Git into a command to be executed using
201these rules:
202
203 1. If the helper string begins with "!", it is considered a shell
204 snippet, and everything after the "!" becomes the command.
205
206 2. Otherwise, if the helper string begins with an absolute path, the
207 verbatim helper string becomes the command.
208
209 3. Otherwise, the string "git credential-" is prepended to the helper
210 string, and the result becomes the command.
211
212The resulting command then has an "operation" argument appended to it
213(see below for details), and the result is executed by the shell.
214
215Here are some example specifications:
216
217----------------------------------------------------
218# run "git credential-foo"
219foo
220
221# same as above, but pass an argument to the helper
222foo --bar=baz
223
224# the arguments are parsed by the shell, so use shell
225# quoting if necessary
226foo --bar="whitespace arg"
227
228# you can also use an absolute path, which will not use the git wrapper
229/path/to/my/helper --with-arguments
230
231# or you can specify your own shell snippet
232!f() { echo "password=`cat $HOME/.secret`"; }; f
233----------------------------------------------------
234
235Generally speaking, rule (3) above is the simplest for users to specify.
236Authors of credential helpers should make an effort to assist their
237users by naming their program "git-credential-$NAME", and putting it in
238the `$PATH` or `$GIT_EXEC_PATH` during installation, which will allow a
239user to enable it with `git config credential.helper $NAME`.
240
241When a helper is executed, it will have one "operation" argument
242appended to its command line, which is one of:
243
244`get`::
245
246Return a matching credential, if any exists.
247
248`store`::
249
250Store the credential, if applicable to the helper.
251
252`erase`::
253
254Remove a matching credential, if any, from the helper's storage.
255
256The details of the credential will be provided on the helper's stdin
257stream. The exact format is the same as the input/output format of the
258`git credential` plumbing command (see the section `INPUT/OUTPUT
259FORMAT` in linkgit:git-credential[1] for a detailed specification).
260
261For a `get` operation, the helper should produce a list of attributes on
262stdout in the same format (see linkgit:git-credential[1] for common
263attributes). A helper is free to produce a subset, or even no values at
264all if it has nothing useful to provide. Any provided attributes will
265overwrite those already known about by Git. If a helper outputs a
266`quit` attribute with a value of `true` or `1`, no further helpers will
267be consulted, nor will the user be prompted (if no credential has been
268provided, the operation will then fail).
269
270For a `store` or `erase` operation, the helper's output is ignored.
271If it fails to perform the requested operation, it may complain to
272stderr to inform the user. If it does not support the requested
273operation (e.g., a read-only store), it should silently ignore the
274request.
275
276If a helper receives any other operation, it should silently ignore the
277request. This leaves room for future operations to be added (older
278helpers will just ignore the new requests).
Junio C Hamano0df92712011-12-21 22:30:44279
280GIT
281---
282Part of the linkgit:git[1] suite