blob: b2114403731157cbb370bff1d450fd52ee56f0fb [file] [log] [blame]
Junio C Hamano8edb4c72012-07-09 20:33:551git-credential(1)
2=================
3
4NAME
5----
Junio C Hamano62e79372012-08-08 22:53:356git-credential - Retrieve and store user credentials
Junio C Hamano8edb4c72012-07-09 20:33:557
8SYNOPSIS
9--------
10------------------
11git credential <fill|approve|reject>
12------------------
13
14DESCRIPTION
15-----------
16
17Git has an internal interface for storing and retrieving credentials
18from system-specific helpers, as well as prompting the user for
19usernames and passwords. The git-credential command exposes this
20interface to scripts which may want to retrieve, store, or prompt for
Junio C Hamano076ffcc2013-02-06 05:13:2121credentials in the same manner as Git. The design of this scriptable
Junio C Hamano8edb4c72012-07-09 20:33:5522interface models the internal C API; see
Junio C Hamanoe6f28d02013-09-17 21:34:0023link:technical/api-credentials.html[the Git credential API] for more
Junio C Hamano8edb4c72012-07-09 20:33:5524background on the concepts.
25
26git-credential takes an "action" option on the command-line (one of
27`fill`, `approve`, or `reject`) and reads a credential description
28on stdin (see <<IOFMT,INPUT/OUTPUT FORMAT>>).
29
30If the action is `fill`, git-credential will attempt to add "username"
31and "password" attributes to the description by reading config files,
32by contacting any configured credential helpers, or by prompting the
33user. The username and password attributes of the credential
34description are then printed to stdout together with the attributes
35already provided.
36
37If the action is `approve`, git-credential will send the description
38to any configured credential helpers, which may store the credential
39for later use.
40
41If the action is `reject`, git-credential will send the description to
42any configured credential helpers, which may erase any stored
43credential matching the description.
44
45If the action is `approve` or `reject`, no output should be emitted.
46
47TYPICAL USE OF GIT CREDENTIAL
48-----------------------------
49
50An application using git-credential will typically use `git
51credential` following these steps:
52
53 1. Generate a credential description based on the context.
54+
55For example, if we want a password for
56`https://example.com/foo.git`, we might generate the following
57credential description (don't forget the blank line at the end; it
58tells `git credential` that the application finished feeding all the
Junio C Hamanoa080bc32013-04-12 21:33:0159information it has):
Junio C Hamano8edb4c72012-07-09 20:33:5560
61 protocol=https
62 host=example.com
63 path=foo.git
64
65 2. Ask git-credential to give us a username and password for this
66 description. This is done by running `git credential fill`,
67 feeding the description from step (1) to its standard input. The complete
68 credential description (including the credential per se, i.e. the
69 login and password) will be produced on standard output, like:
70
71protocol=https
72host=example.com
73username=bob
74password=secr3t
75+
76In most cases, this means the attributes given in the input will be
Junio C Hamano076ffcc2013-02-06 05:13:2177repeated in the output, but Git may also modify the credential
Junio C Hamano8edb4c72012-07-09 20:33:5578description, for example by removing the `path` attribute when the
79protocol is HTTP(s) and `credential.useHttpPath` is false.
80+
81If the `git credential` knew about the password, this step may
82not have involved the user actually typing this password (the
83user may have typed a password to unlock the keychain instead,
84or no user interaction was done if the keychain was already
85unlocked) before it returned `password=secr3t`.
86
87 3. Use the credential (e.g., access the URL with the username and
88 password from step (2)), and see if it's accepted.
89
90 4. Report on the success or failure of the password. If the
91 credential allowed the operation to complete successfully, then
92 it can be marked with an "approve" action to tell `git
93 credential` to reuse it in its next invocation. If the credential
94 was rejected during the operation, use the "reject" action so
95 that `git credential` will ask for a new password in its next
96 invocation. In either case, `git credential` should be fed with
97 the credential description obtained from step (2) (which also
98 contain the ones provided in step (1)).
99
100[[IOFMT]]
101INPUT/OUTPUT FORMAT
102-------------------
103
104`git credential` reads and/or writes (depending on the action used)
Junio C Hamano44dcd492012-07-24 04:35:38105credential information in its standard input/output. This information
Junio C Hamano8edb4c72012-07-09 20:33:55106can correspond either to keys for which `git credential` will obtain
107the login/password information (e.g. host, protocol, path), or to the
108actual credential data to be obtained (login/password).
109
Junio C Hamano44dcd492012-07-24 04:35:38110The credential is split into a set of named attributes, with one
111attribute per line. Each attribute is
Junio C Hamano8edb4c72012-07-09 20:33:55112specified by a key-value pair, separated by an `=` (equals) sign,
113followed by a newline. The key may contain any bytes except `=`,
114newline, or NUL. The value may contain any bytes except newline or NUL.
115In both cases, all bytes are treated as-is (i.e., there is no quoting,
116and one cannot transmit a value with newline or NUL in it). The list of
117attributes is terminated by a blank line or end-of-file.
Junio C Hamano44dcd492012-07-24 04:35:38118Git understands the following attributes:
Junio C Hamano8edb4c72012-07-09 20:33:55119
120`protocol`::
121
122The protocol over which the credential will be used (e.g.,
123`https`).
124
125`host`::
126
127The remote hostname for a network credential.
128
129`path`::
130
131The path with which the credential will be used. E.g., for
132accessing a remote https repository, this will be the
133repository's path on the server.
134
135`username`::
136
137The credential's username, if we already have one (e.g., from a
138URL, from the user, or from a previously run helper).
139
140`password`::
141
142The credential's password, if we are asking it to be stored.
Junio C Hamano44dcd492012-07-24 04:35:38143
144`url`::
145
146When this special attribute is read by `git credential`, the
147value is parsed as a URL and treated as if its constituent parts
148were read (e.g., `url=https://example.com` would behave as if
149`protocol=https` and `host=example.com` had been provided). This
150can help callers avoid parsing URLs themselves. Note that any
151components which are missing from the URL (e.g., there is no
152username in the example above) will be set to empty; if you want
153to provide a URL and override some attributes, provide the URL
154attribute first, followed by any overrides.