{"id":4101,"date":"2022-12-20T17:39:23","date_gmt":"2022-12-20T20:39:23","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/gitcredentials-man7\/"},"modified":"2022-12-20T17:39:23","modified_gmt":"2022-12-20T20:39:23","slug":"gitcredentials-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/gitcredentials-man7\/","title":{"rendered":"GITCREDENTIALS (man7)"},"content":{"rendered":"<h1 align=\"center\">GITCREDENTIALS<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#REQUESTING CREDENTIALS\">REQUESTING CREDENTIALS<\/a><br \/> <a href=\"#AVOIDING REPETITION\">AVOIDING REPETITION<\/a><br \/> <a href=\"#CREDENTIAL CONTEXTS\">CREDENTIAL CONTEXTS<\/a><br \/> <a href=\"#CONFIGURATION OPTIONS\">CONFIGURATION OPTIONS<\/a><br \/> <a href=\"#CUSTOM HELPERS\">CUSTOM HELPERS<\/a><br \/> <a href=\"#GIT\">GIT<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">gitcredentials \u2212 Providing usernames and passwords to Git<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">git config credential.https:\/\/example.com.username myusername <br \/> git config credential.helper &#8220;$helper $options&#8221;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Git will sometimes need credentials from the user in order to perform operations; for example, it may need to ask for a username and password in order to access a remote repository over HTTP. This manual describes the mechanisms Git uses to request these credentials, as well as some features to avoid inputting these credentials repeatedly.<\/p>\n<h2>REQUESTING CREDENTIALS <a name=\"REQUESTING CREDENTIALS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Without any credential helpers defined, Git will try the following strategies to ask the user for usernames and passwords:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">1. If the <b>GIT_ASKPASS<\/b> environment variable is set, the program specified by the variable is invoked. A suitable prompt is provided to the program on the command line, and the user\u2019s input is read from its standard output.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">2. Otherwise, if the <b>core.askPass<\/b> configuration variable is set, its value is used as above.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">3. Otherwise, if the <b>SSH_ASKPASS<\/b> environment variable is set, its value is used as above.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">4. Otherwise, the user is prompted on the terminal.<\/p>\n<h2>AVOIDING REPETITION <a name=\"AVOIDING REPETITION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">It can be cumbersome to input the same credentials over and over. Git provides two methods to reduce this annoyance:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">1. Static configuration of usernames for a given authentication context.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">2. Credential helpers to cache or store passwords, or to interact with a system password wallet or keychain.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The first is simple and appropriate if you do not have secure storage available for a password. It is generally configured by adding this to your config:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">[credential &#8220;https:\/\/example.com&#8221;] <br \/> username = me<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Credential helpers, on the other hand, are external programs from which Git can request both usernames and passwords; they typically interface with secure storage provided by the OS or other programs.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To use a helper, you must first select one to use. Git currently includes the following helpers:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">cache<\/p>\n<p style=\"margin-left:17%;\">Cache credentials in memory for a short period of time. See <b>git-credential-cache<\/b>(1) for details.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">store<\/p>\n<p style=\"margin-left:17%;\">Store credentials indefinitely on disk. See <b>git-credential-store<\/b>(1) for details.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">You may also have third\u2212party helpers installed; search for <b>credential\u2212*<\/b> in the output of <b>git help \u2212a<\/b>, and consult the documentation of individual helpers. Once you have selected a helper, you can tell Git to use it by putting its name into the credential.helper variable.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">1. Find a helper.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">$ git help \u2212a | grep credential\u2212 <br \/> credential\u2212foo<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">2. Read its description.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">$ git help credential\u2212foo<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">3. Tell Git to use it.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">$ git config \u2212\u2212global credential.helper foo<\/p>\n<h2>CREDENTIAL CONTEXTS <a name=\"CREDENTIAL CONTEXTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Git considers each credential to have a context defined by a URL. This context is used to look up context\u2212specific configuration, and is passed to any helpers, which may use it as an index into secure storage.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For instance, imagine we are accessing <b>https:\/\/example.com\/foo.git<\/b>. When Git looks into a config file to see if a section matches this context, it will consider the two a match if the context is a more\u2212specific subset of the pattern in the config file. For example, if you have this in your config file:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">[credential &#8220;https:\/\/example.com&#8221;] <br \/> username = foo<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">then we will match: both protocols are the same, both hosts are the same, and the &#8220;pattern&#8221; URL does not care about the path component at all. However, this context would not match:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">[credential &#8220;https:\/\/kernel.org&#8221;] <br \/> username = foo<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">because the hostnames differ. Nor would it match <b>foo.example.com<\/b>; Git compares hostnames exactly, without considering whether two hosts are part of the same domain. Likewise, a config entry for <b>http:\/\/example.com<\/b> would not match: Git compares the protocols exactly. However, you may use wildcards in the domain name and other pattern matching techniques as with the <b>http.<url>.*<\/b> options.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the &#8220;pattern&#8221; URL does include a path component, then this too must match exactly: the context <b>https:\/\/example.com\/bar\/baz.git<\/b> will match a config entry for <b>https:\/\/example.com\/bar\/baz.git<\/b> (in addition to matching the config entry for <b>https:\/\/example.com<\/b>) but will not match a config entry for <b>https:\/\/example.com\/bar<\/b>.<\/p>\n<h2>CONFIGURATION OPTIONS <a name=\"CONFIGURATION OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Options for a credential context can be configured either in <b>credential.*<\/b> (which applies to all credentials), or <b>credential.<url>.*<\/b>, where <url> matches the context as described above.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The following options are available in either location:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">helper<\/p>\n<p style=\"margin-left:17%;\">The name of an external credential helper, and any associated options. If the helper name is not an absolute path, then the string <b>git credential\u2212<\/b> is prepended. The resulting string is executed by the shell (so, for example, setting this to <b>foo \u2212\u2212option=bar<\/b> will execute <b>git credential\u2212foo \u2212\u2212option=bar<\/b> via the shell. See the manual of specific helpers for examples of their use.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">If there are multiple instances of the <b>credential.helper<\/b> configuration variable, each helper will be tried in turn, and may provide a username, password, or nothing. Once Git has acquired both a username and a password, no more helpers will be tried.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">If <b>credential.helper<\/b> is configured to the empty string, this resets the helper list to empty (so you may override a helper set by a lower\u2212priority config file by configuring the empty\u2212string helper, followed by whatever set of helpers you would like).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">username<\/p>\n<p style=\"margin-left:17%;\">A default username, if one is not provided in the URL.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">useHttpPath<\/p>\n<p style=\"margin-left:17%;\">By default, Git does not consider the &#8220;path&#8221; component of an http URL to be worth matching via external helpers. This means that a credential stored for <b>https:\/\/example.com\/foo.git<\/b> will also be used for <b>https:\/\/example.com\/bar.git<\/b>. If you do want to distinguish these cases, set this option to <b>true<\/b>.<\/p>\n<h2>CUSTOM HELPERS <a name=\"CUSTOM HELPERS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">You can write your own custom helpers to interface with any system in which you keep credentials.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Credential helpers are programs executed by Git to fetch or save credentials from and to long\u2212term storage (where &#8220;long\u2212term&#8221; is simply longer than a single Git process; e.g., credentials may be stored in\u2212memory for a few minutes, or indefinitely on disk).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Each helper is specified by a single string in the configuration variable <b>credential.helper<\/b> (and others, see <b>git-config<\/b>(1)). The string is transformed by Git into a command to be executed using these rules:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">1. If the helper string begins with &#8220;!&#8221;, it is considered a shell snippet, and everything after the &#8220;!&#8221; becomes the command.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">2. Otherwise, if the helper string begins with an absolute path, the verbatim helper string becomes the command.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">3. Otherwise, the string &#8220;git credential\u2212&#8221; is prepended to the helper string, and the result becomes the command.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The resulting command then has an &#8220;operation&#8221; argument appended to it (see below for details), and the result is executed by the shell.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Here are some example specifications:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># run &#8220;git credential\u2212foo&#8221; <br \/> [credential] <br \/> helper = foo<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># same as above, but pass an argument to the helper <br \/> [credential] <br \/> helper = &#8220;foo \u2212\u2212bar=baz&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># the arguments are parsed by the shell, so use shell <br \/> # quoting if necessary <br \/> [credential] <br \/> helper = &#8220;foo \u2212\u2212bar=&#8217;whitespace arg'&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># you can also use an absolute path, which will not use the git wrapper <br \/> [credential] <br \/> helper = &#8220;\/path\/to\/my\/helper \u2212\u2212with\u2212arguments&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"># or you can specify your own shell snippet <br \/> [credential &#8220;https:\/\/example.com&#8221;] <br \/> username = your_user <br \/> helper = &#8220;!f() { test &#8220;$1&#8221; = get &#038;&#038; echo &#8220;password=$(cat $HOME\/.secret)&#8221;; }; f&#8221;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Generally speaking, rule (3) above is the simplest for users to specify. Authors of credential helpers should make an effort to assist their users by naming their program &#8220;git\u2212credential\u2212$NAME&#8221;, and putting it in the <b>$PATH<\/b> or <b>$GIT_EXEC_PATH<\/b> during installation, which will allow a user to enable it with <b>git config credential.helper $NAME<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When a helper is executed, it will have one &#8220;operation&#8221; argument appended to its command line, which is one of:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get<\/b><\/p>\n<p style=\"margin-left:17%;\">Return a matching credential, if any exists.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>store<\/b><\/p>\n<p style=\"margin-left:17%;\">Store the credential, if applicable to the helper.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>erase<\/b><\/p>\n<p style=\"margin-left:17%;\">Remove a matching credential, if any, from the helper\u2019s storage.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The details of the credential will be provided on the helper\u2019s stdin stream. The exact format is the same as the input\/output format of the <b>git credential<\/b> plumbing command (see the section <b>INPUT\/OUTPUT FORMAT<\/b> in <b>git-credential<\/b>(1) for a detailed specification).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a <b>get<\/b> operation, the helper should produce a list of attributes on stdout in the same format (see <b>git-credential<\/b>(1) for common attributes). A helper is free to produce a subset, or even no values at all if it has nothing useful to provide. Any provided attributes will overwrite those already known about by Git\u2019s credential subsystem.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">While it is possible to override all attributes, well behaving helpers should refrain from doing so for any attribute other than username and password.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If a helper outputs a <b>quit<\/b> attribute with a value of <b>true<\/b> or <b>1<\/b>, no further helpers will be consulted, nor will the user be prompted (if no credential has been provided, the operation will then fail).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Similarly, no more helpers will be consulted once both username and password had been provided.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a <b>store<\/b> or <b>erase<\/b> operation, the helper\u2019s output is ignored.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If a helper fails to perform the requested operation or needs to notify the user of a potential issue, it may write to stderr.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If it does not support the requested operation (e.g., a read\u2212only store), it should silently ignore the request.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If a helper receives any other operation, it should silently ignore the request. This leaves room for future operations to be added (older helpers will just ignore the new requests).<\/p>\n<h2>GIT <a name=\"GIT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Part of the <b>git<\/b>(1) suite<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  gitcredentials \u2212 Providing usernames and passwords to Git <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,1180,972],"class_list":["post-4101","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-gitcredentials","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4101"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4101\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}