blob: f18673017f577f523b1190ce87ce2d448e4dbd70 [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------------------
Junio C Hamano59a32b02021-12-10 22:53:3811'git credential' (fill|approve|reject)
Junio C Hamano8edb4c72012-07-09 20:33:5512------------------
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 Hamano2267da52019-12-18 23:09:4322interface models the internal C API; see credential.h for more
Junio C Hamano8edb4c72012-07-09 20:33:5523background on the concepts.
24
25git-credential takes an "action" option on the command-line (one of
26`fill`, `approve`, or `reject`) and reads a credential description
27on stdin (see <<IOFMT,INPUT/OUTPUT FORMAT>>).
28
29If the action is `fill`, git-credential will attempt to add "username"
30and "password" attributes to the description by reading config files,
31by contacting any configured credential helpers, or by prompting the
32user. The username and password attributes of the credential
33description are then printed to stdout together with the attributes
34already provided.
35
36If the action is `approve`, git-credential will send the description
37to any configured credential helpers, which may store the credential
38for later use.
39
40If the action is `reject`, git-credential will send the description to
41any configured credential helpers, which may erase any stored
42credential matching the description.
43
44If the action is `approve` or `reject`, no output should be emitted.
45
46TYPICAL USE OF GIT CREDENTIAL
47-----------------------------
48
49An application using git-credential will typically use `git
50credential` following these steps:
51
52 1. Generate a credential description based on the context.
53+
54For example, if we want a password for
55`https://example.com/foo.git`, we might generate the following
56credential description (don't forget the blank line at the end; it
57tells `git credential` that the application finished feeding all the
Junio C Hamanoa080bc32013-04-12 21:33:0158information it has):
Junio C Hamano8edb4c72012-07-09 20:33:5559
60 protocol=https
61 host=example.com
62 path=foo.git
63
64 2. Ask git-credential to give us a username and password for this
65 description. This is done by running `git credential fill`,
66 feeding the description from step (1) to its standard input. The complete
67 credential description (including the credential per se, i.e. the
68 login and password) will be produced on standard output, like:
69
70protocol=https
71host=example.com
72username=bob
73password=secr3t
74+
75In most cases, this means the attributes given in the input will be
Junio C Hamano076ffcc2013-02-06 05:13:2176repeated in the output, but Git may also modify the credential
Junio C Hamano8edb4c72012-07-09 20:33:5577description, for example by removing the `path` attribute when the
78protocol is HTTP(s) and `credential.useHttpPath` is false.
79+
80If the `git credential` knew about the password, this step may
81not have involved the user actually typing this password (the
82user may have typed a password to unlock the keychain instead,
83or no user interaction was done if the keychain was already
84unlocked) before it returned `password=secr3t`.
85
86 3. Use the credential (e.g., access the URL with the username and
87 password from step (2)), and see if it's accepted.
88
89 4. Report on the success or failure of the password. If the
90 credential allowed the operation to complete successfully, then
91 it can be marked with an "approve" action to tell `git
92 credential` to reuse it in its next invocation. If the credential
93 was rejected during the operation, use the "reject" action so
94 that `git credential` will ask for a new password in its next
95 invocation. In either case, `git credential` should be fed with
96 the credential description obtained from step (2) (which also
97 contain the ones provided in step (1)).
98
99[[IOFMT]]
100INPUT/OUTPUT FORMAT
101-------------------
102
103`git credential` reads and/or writes (depending on the action used)
Junio C Hamano44dcd492012-07-24 04:35:38104credential information in its standard input/output. This information
Junio C Hamano8edb4c72012-07-09 20:33:55105can correspond either to keys for which `git credential` will obtain
Junio C Hamano306e7632020-05-14 23:03:19106the login information (e.g. host, protocol, path), or to the actual
107credential data to be obtained (username/password).
Junio C Hamano8edb4c72012-07-09 20:33:55108
Junio C Hamano44dcd492012-07-24 04:35:38109The credential is split into a set of named attributes, with one
Junio C Hamano306e7632020-05-14 23:03:19110attribute per line. Each attribute is specified by a key-value pair,
111separated by an `=` (equals) sign, followed by a newline.
112
113The key may contain any bytes except `=`, newline, or NUL. The value may
114contain any bytes except newline or NUL.
115
Junio C Hamano8edb4c72012-07-09 20:33:55116In both cases, all bytes are treated as-is (i.e., there is no quoting,
117and one cannot transmit a value with newline or NUL in it). The list of
118attributes is terminated by a blank line or end-of-file.
Junio C Hamano306e7632020-05-14 23:03:19119
Junio C Hamano44dcd492012-07-24 04:35:38120Git understands the following attributes:
Junio C Hamano8edb4c72012-07-09 20:33:55121
122`protocol`::
123
124The protocol over which the credential will be used (e.g.,
125`https`).
126
127`host`::
128
Junio C Hamano306e7632020-05-14 23:03:19129The remote hostname for a network credential. This includes
130the port number if one was specified (e.g., "example.com:8088").
Junio C Hamano8edb4c72012-07-09 20:33:55131
132`path`::
133
134The path with which the credential will be used. E.g., for
135accessing a remote https repository, this will be the
136repository's path on the server.
137
138`username`::
139
140The credential's username, if we already have one (e.g., from a
Junio C Hamano306e7632020-05-14 23:03:19141URL, the configuration, the user, or from a previously run helper).
Junio C Hamano8edb4c72012-07-09 20:33:55142
143`password`::
144
145The credential's password, if we are asking it to be stored.
Junio C Hamano44dcd492012-07-24 04:35:38146
147`url`::
148
149When this special attribute is read by `git credential`, the
150value is parsed as a URL and treated as if its constituent parts
151were read (e.g., `url=https://example.com` would behave as if
152`protocol=https` and `host=example.com` had been provided). This
Junio C Hamano306e7632020-05-14 23:03:19153can help callers avoid parsing URLs themselves.
Junio C Hamano0beab6c2020-05-26 18:32:25154+
155Note that specifying a protocol is mandatory and if the URL
156doesn't specify a hostname (e.g., "cert:///path/to/file") the
157credential will contain a hostname attribute whose value is an
158empty string.
159+
160Components which are missing from the URL (e.g., there is no
161username in the example above) will be left unset.
Junio C Hamanobe601db2021-05-07 04:20:28162
163GIT
164---
165Part of the linkgit:git[1] suite