Git Reference ยท Setup and Basics
git credential command
Reference for git credential: the fill, approve and reject actions, the key=value protocol, credential helpers such as store and cache, and URL matching rules.
git credential is the low-level interface between Git and credential helpers, the small programs that remember usernames and passwords for HTTP(S) remotes. Git itself calls it when a fetch or push needs authentication; you rarely type it by hand, but it is the right tool to test a helper, debug a login loop, or reuse Git's credential storage in your own scripts.
You describe the thing you need credentials for as lines of key=value on standard input, ended by a blank line. The command answers with the same format.
git credential fill|approve|reject
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git credential fill < description git credential approve < description-with-credential git credential reject < description-with-credential
| Action | Input | What happens |
|---|---|---|
fill |
What you know (protocol, host, maybe username). | Asks each configured helper in turn for a match; if still incomplete, prompts on the terminal. Prints the full description including username and password. |
approve |
A complete credential that worked. | Tells all helpers to store it. |
reject |
A credential that failed. | Tells all helpers to forget it. |
Input and output attributes:
| Key | Meaning |
|---|---|
protocol, host, path |
Where the credential is used. host may include :port. path is only sent if credential.useHttpPath is true. |
url |
Shortcut that is expanded into protocol, host, path, username and password. |
username, password |
The secret pair. |
password_expiry_utc |
Unix time after which the password should no longer be used (Git 2.40 and later). |
oauth_refresh_token |
Extra token kept by helpers that support refreshing. |
wwwauth[] |
Authentication challenges from the server, passed to helpers. |
capability[] |
Features the sender understands. |
quit=1 |
A helper can ask Git to stop trying others. |
Errors: with no helper and no terminal, fill fails with fatal: could not read Username for 'https://host': terminal prompts disabled (the example shows the same when GIT_TERMINAL_PROMPT=0 is set). A malformed line (without =) is a fatal error.
Usage notes
- Helpers are named in
credential.helper. A bare namefoorunsgit-credential-foo; an absolute path or!commandruns that directly. The list is tried in order, andcredential.helper=(empty) resets the list. - Built-in helpers.
storewrites plain text to~/.git-credentialsor a file you choose,cachekeeps secrets in memory for a while (--timeout=<seconds>, not available on Windows), and platform helpers use the keychain:osxkeychain,wincred/Git Credential Manager,libsecret. Prefer a keychain-backed helper;storeleaves tokens readable on disk. - Matching. A stored entry matches by protocol and host; the path only participates when
useHttpPathis on, which is how you keep different tokens for different repositories on one host.credential.<url>.usernamepresets a user name for a URL. - Helper protocol. Git runs the helper with the argument
get,storeoreraseand feeds it the same lines. Writing your own helper is a ten-line script that reads stdin and printsusername=andpassword=. - Avoid passwords in URLs.
https://user:secret@host/...is saved verbatim in.git/configand appears in process listings. Use a helper, or SSH keys, instead. - Debugging a loop. If Git keeps asking, run
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git fetchand check thatapproveactually ran; a helper that is not found fails silently. - Do not paste real secrets into shared terminals or logs when testing; the sample values here are made up.
Related
- git config, git clone, git push, Git URLs
- Lessons: Signing and Security, Remotes