blob: f3a75d1ce1c5a2709b452faca76f5f6f1cdb7de0 [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
104If there are multiple instances of the `credential.helper` configuration
105variable, each helper will be tried in turn, and may provide a username,
Junio C Hamano076ffcc2013-02-06 05:13:21106password, or nothing. Once Git has acquired both a username and a
Junio C Hamano0df92712011-12-21 22:30:44107password, no more helpers will be tried.
108
Junio C Hamano4ba4a782016-04-03 19:11:32109If `credential.helper` is configured to the empty string, this resets
110the helper list to empty (so you may override a helper set by a
111lower-priority config file by configuring the empty-string helper,
112followed by whatever set of helpers you would like).
113
Junio C Hamano0df92712011-12-21 22:30:44114
115CREDENTIAL CONTEXTS
116-------------------
117
118Git considers each credential to have a context defined by a URL. This context
119is used to look up context-specific configuration, and is passed to any
120helpers, which may use it as an index into secure storage.
121
Junio C Hamano076ffcc2013-02-06 05:13:21122For instance, imagine we are accessing `https://example.com/foo.git`. When Git
Junio C Hamano0df92712011-12-21 22:30:44123looks into a config file to see if a section matches this context, it will
124consider the two a match if the context is a more-specific subset of the
125pattern in the config file. For example, if you have this in your config file:
126
127--------------------------------------
128[credential "https://example.com"]
129username = foo
130--------------------------------------
131
132then we will match: both protocols are the same, both hosts are the same, and
133the "pattern" URL does not care about the path component at all. However, this
134context would not match:
135
136--------------------------------------
137[credential "https://kernel.org"]
138username = foo
139--------------------------------------
140
Junio C Hamano076ffcc2013-02-06 05:13:21141because the hostnames differ. Nor would it match `foo.example.com`; Git
Junio C Hamano0df92712011-12-21 22:30:44142compares hostnames exactly, without considering whether two hosts are part of
143the same domain. Likewise, a config entry for `http://example.com` would not
Junio C Hamano076ffcc2013-02-06 05:13:21144match: Git compares the protocols exactly.
Junio C Hamano0df92712011-12-21 22:30:44145
146
147CONFIGURATION OPTIONS
148---------------------
149
150Options for a credential context can be configured either in
Junio C Hamanob76a6862012-05-02 22:02:46151`credential.*` (which applies to all credentials), or
152`credential.<url>.*`, where <url> matches the context as described
Junio C Hamano0df92712011-12-21 22:30:44153above.
154
155The following options are available in either location:
156
157helper::
158
159The name of an external credential helper, and any associated options.
160If the helper name is not an absolute path, then the string `git
161credential-` is prepended. The resulting string is executed by the
162shell (so, for example, setting this to `foo --option=bar` will execute
163`git credential-foo --option=bar` via the shell. See the manual of
164specific helpers for examples of their use.
165
166username::
167
168A default username, if one is not provided in the URL.
169
170useHttpPath::
171
Junio C Hamano076ffcc2013-02-06 05:13:21172By default, Git does not consider the "path" component of an http URL
Junio C Hamano0df92712011-12-21 22:30:44173to be worth matching via external helpers. This means that a credential
174stored for `https://example.com/foo.git` will also be used for
175`https://example.com/bar.git`. If you do want to distinguish these
176cases, set this option to `true`.
177
178
179CUSTOM HELPERS
180--------------
181
182You can write your own custom helpers to interface with any system in
Junio C Hamano076ffcc2013-02-06 05:13:21183which you keep credentials. See the documentation for Git's
Junio C Hamano0df92712011-12-21 22:30:44184link:technical/api-credentials.html[credentials API] for details.
185
186GIT
187---
188Part of the linkgit:git[1] suite