interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / gitcredentials.adoc

335 lines · 12183 bytes Raw Blame History
1gitcredentials(7)
2=================
3
4NAME
5----
6gitcredentials - Providing usernames and passwords to Git
7
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. Some remotes accept
21a personal access token or OAuth access token as a password. This
22manual describes the mechanisms Git uses to request these credentials,
23as well as some features to avoid inputting these credentials repeatedly.
24
25REQUESTING CREDENTIALS
26----------------------
27
28Without any credential helpers defined, Git will try the following
29strategies to ask the user for usernames and passwords:
30
311. 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.
35
362. Otherwise, if the `core.askPass` configuration variable is set, its
37 value is used as above.
38
393. Otherwise, if the `SSH_ASKPASS` environment variable is set, its
40 value is used as above.
41
424. Otherwise, the user is prompted on the terminal.
43
44AVOIDING REPETITION
45-------------------
46
47It can be cumbersome to input the same credentials over and over. Git
48provides two methods to reduce this annoyance:
49
501. Static configuration of usernames for a given authentication context.
51
522. Credential helpers to cache or store passwords, or to interact with
53 a system password wallet or keychain.
54
55The first is simple and appropriate if you do not have secure storage available
56for a password. It is generally configured by adding this to your config:
57
58---------------------------------------
59[credential "https://example.com"]
60 username = me
61---------------------------------------
62
63Credential helpers, on the other hand, are external programs from which Git can
64request both usernames and passwords; they typically interface with secure
65storage provided by the OS or other programs. Alternatively, a
66credential-generating helper might generate credentials for certain servers via
67some API.
68
69To use a helper, you must first select one to use (see below for a list).
70
71You may also have third-party helpers installed; search for
72`credential-*` in the output of `git help -a`, and consult the
73documentation of individual helpers. Once you have selected a helper,
74you can tell Git to use it by putting its name into the
75credential.helper variable.
76
771. Find a helper.
78+
79-------------------------------------------
80$ git help -a | grep credential-
81credential-foo
82-------------------------------------------
83
842. Read its description.
85+
86-------------------------------------------
87$ git help credential-foo
88-------------------------------------------
89
903. Tell Git to use it.
91+
92-------------------------------------------
93$ git config --global credential.helper foo
94-------------------------------------------
95
96=== Available helpers
97
98Git currently includes the following helpers:
99
100cache::
101
102 Cache credentials in memory for a short period of time. See
103 linkgit:git-credential-cache[1] for details.
104
105store::
106
107 Store credentials indefinitely on disk. See
108 linkgit:git-credential-store[1] for details.
109
110Popular helpers with secure persistent storage include:
111
112 - git-credential-libsecret (Linux)
113
114 - git-credential-osxkeychain (macOS)
115
116 - git-credential-wincred (Windows)
117
118 - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
119
120The community maintains a comprehensive list of Git credential helpers at
121https://git-scm.com/doc/credential-helpers.
122
123=== OAuth
124
125An alternative to inputting passwords or personal access tokens is to use an
126OAuth credential helper. Initial authentication opens a browser window to the
127host. Subsequent authentication happens in the background. Many popular Git
128hosts support OAuth.
129
130Popular helpers with OAuth support include:
131
132 - https://github.com/git-ecosystem/git-credential-manager[Git Credential Manager] (cross platform, included in Git for Windows)
133
134 - https://github.com/hickford/git-credential-oauth[git-credential-oauth] (cross platform, included in many Linux distributions)
135
136CREDENTIAL CONTEXTS
137-------------------
138
139Git considers each credential to have a context defined by a URL. This context
140is used to look up context-specific configuration, and is passed to any
141helpers, which may use it as an index into secure storage.
142
143For instance, imagine we are accessing `https://example.com/foo.git`. When Git
144looks into a config file to see if a section matches this context, it will
145consider the two a match if the context is a more-specific subset of the
146pattern in the config file. For example, if you have this in your config file:
147
148--------------------------------------
149[credential "https://example.com"]
150 username = foo
151--------------------------------------
152
153then we will match: both protocols are the same and both hosts are the same.
154However, this context would not match:
155
156--------------------------------------
157[credential "https://kernel.org"]
158 username = foo
159--------------------------------------
160
161because the hostnames differ. Nor would it match `foo.example.com`; Git
162compares hostnames exactly, without considering whether two hosts are part of
163the same domain. Likewise, a config entry for `http://example.com` would not
164match: Git compares the protocols exactly. However, you may use wildcards in
165the domain name and other pattern matching techniques as with the `http.<URL>.*`
166options.
167
168If the "pattern" URL does include a path component, then this must match
169as a prefix path: the context `https://example.com/bar` will match a config
170entry for `https://example.com/bar/baz.git` but will not match a config entry for
171`https://example.com/other/repo.git` or `https://example.com/barry/repo.git`
172(even though it is a string prefix).
173
174
175CONFIGURATION OPTIONS
176---------------------
177
178Options for a credential context can be configured either in
179`credential.*` (which applies to all credentials), or
180`credential.<URL>.*`, where <URL> matches the context as described
181above.
182
183The following options are available in either location:
184
185helper::
186
187 The name of an external credential helper, and any associated options.
188 If the helper name is not an absolute path, then the string `git
189 credential-` is prepended. The resulting string is executed by the
190 shell (so, for example, setting this to `foo --option=bar` will execute
191 `git credential-foo --option=bar` via the shell. See the manual of
192 specific helpers for examples of their use.
193+
194If there are multiple instances of the `credential.helper` configuration
195variable, each helper will be tried in turn, and may provide a username,
196password, or nothing. Once Git has acquired both a username and a
197non-expired password, no more helpers will be tried.
198+
199If `credential.helper` is configured to the empty string, this resets
200the helper list to empty (so you may override a helper set by a
201lower-priority config file by configuring the empty-string helper,
202followed by whatever set of helpers you would like).
203
204username::
205
206 A default username, if one is not provided in the URL.
207
208useHttpPath::
209
210 By default, Git does not consider the "path" component of an http URL
211 to be worth matching via external helpers. This means that a credential
212 stored for `https://example.com/foo.git` will also be used for
213 `https://example.com/bar.git`. If you do want to distinguish these
214 cases, set this option to `true`.
215
216
217CUSTOM HELPERS
218--------------
219
220You can write your own custom helpers to interface with any system in
221which you keep credentials.
222
223Credential helpers are programs executed by Git to fetch or save
224credentials from and to long-term storage (where "long-term" is simply
225longer than a single Git process; e.g., credentials may be stored
226in-memory for a few minutes, or indefinitely on disk).
227
228Each helper is specified by a single string in the configuration
229variable `credential.helper` (and others, see linkgit:git-config[1]).
230The string is transformed by Git into a command to be executed using
231these rules:
232
233 1. If the helper string begins with "!", it is considered a shell
234 snippet, and everything after the "!" becomes the command.
235
236 2. Otherwise, if the helper string begins with an absolute path, the
237 verbatim helper string becomes the command.
238
239 3. Otherwise, the string "git credential-" is prepended to the helper
240 string, and the result becomes the command.
241
242The resulting command then has an "operation" argument appended to it
243(see below for details), and the result is executed by the shell.
244
245Here are some example specifications:
246
247----------------------------------------------------
248# run "git credential-foo"
249[credential]
250 helper = foo
251
252# same as above, but pass an argument to the helper
253[credential]
254 helper = "foo --bar=baz"
255
256# the arguments are parsed by the shell, so use shell
257# quoting if necessary
258[credential]
259 helper = "foo --bar='whitespace arg'"
260
261# store helper (discouraged) with custom location for the db file;
262# use `--file ~/.git-secret.txt`, rather than `--file=~/.git-secret.txt`,
263# to allow the shell to expand tilde to the home directory.
264[credential]
265 helper = "store --file ~/.git-secret.txt"
266
267# you can also use an absolute path, which will not use the git wrapper
268[credential]
269 helper = "/path/to/my/helper --with-arguments"
270
271# or you can specify your own shell snippet
272[credential "https://example.com"]
273 username = your_user
274 helper = "!f() { test \"$1\" = get && echo \"password=$(cat $HOME/.secret)\"; }; f"
275----------------------------------------------------
276
277Generally speaking, rule (3) above is the simplest for users to specify.
278Authors of credential helpers should make an effort to assist their
279users by naming their program "git-credential-$NAME", and putting it in
280the `$PATH` or `$GIT_EXEC_PATH` during installation, which will allow a
281user to enable it with `git config credential.helper $NAME`.
282
283When a helper is executed, it will have one "operation" argument
284appended to its command line, which is one of:
285
286`get`::
287
288 Return a matching credential, if any exists.
289
290`store`::
291
292 Store the credential, if applicable to the helper.
293
294`erase`::
295
296 Remove matching credentials, if any, from the helper's storage.
297
298The details of the credential will be provided on the helper's stdin
299stream. The exact format is the same as the input/output format of the
300`git credential` plumbing command (see the section `INPUT/OUTPUT
301FORMAT` in linkgit:git-credential[1] for a detailed specification).
302
303For a `get` operation, the helper should produce a list of attributes on
304stdout in the same format (see linkgit:git-credential[1] for common
305attributes). A helper is free to produce a subset, or even no values at
306all if it has nothing useful to provide. Any provided attributes will
307overwrite those already known about by Git's credential subsystem.
308Unrecognised attributes are silently discarded.
309
310While it is possible to override all attributes, well behaving helpers
311should refrain from doing so for any attribute other than username and
312password.
313
314If a helper outputs a `quit` attribute with a value of `true` or `1`,
315no further helpers will be consulted, nor will the user be prompted
316(if no credential has been provided, the operation will then fail).
317
318Similarly, no more helpers will be consulted once both username and
319password had been provided.
320
321For a `store` or `erase` operation, the helper's output is ignored.
322
323If a helper fails to perform the requested operation or needs to notify
324the user of a potential issue, it may write to stderr.
325
326If it does not support the requested operation (e.g., a read-only store
327or generator), it should silently ignore the request.
328
329If a helper receives any other operation, it should silently ignore the
330request. This leaves room for future operations to be added (older
331helpers will just ignore the new requests).
332
333GIT
334---
335Part of the linkgit:git[1] suite