Git Reference ยท Environment Variables
GIT_TERMINAL_PROMPT
Reference for GIT_TERMINAL_PROMPT and GIT_ASKPASS: stop Git from asking for a username or password in CI and scripts, and see how the prompt chain falls back.
When Git needs a username or password for an HTTP(S) remote and no credential helper supplies one, it asks. Interactively that is helpful. In a cron job, a CI runner or a build script it is a hang: the process sits waiting for input nobody will type.
Setting GIT_TERMINAL_PROMPT=0 turns the terminal prompt off. Git then fails immediately with a clear message instead of waiting. GIT_ASKPASS is the companion that supplies answers from a program instead of a person.
GIT_TERMINAL_PROMPT=0 git fetch # fail fast instead of hanging GIT_ASKPASS=/usr/local/bin/ask-secret git push # let a program answer
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_TERMINAL_PROMPT=<0|1> git <command> GIT_ASKPASS=<program> git <command> git config core.askPass <program>
| Name | Description |
|---|---|
GIT_TERMINAL_PROMPT |
0 (or false) forbids prompting on the terminal. Any other value, or unset, allows it. |
GIT_ASKPASS |
Program started to ask for a username or password; it prints the answer on standard output. Receives the question as its only argument. |
core.askPass |
Configuration form of GIT_ASKPASS. |
SSH_ASKPASS |
Used as a last resort when GIT_ASKPASS and core.askPass are unset, mainly for graphical environments. |
Order of attempts: credential helpers (credential.helper) are asked first. If they cannot answer, Git consults GIT_ASKPASS, then core.askPass, then SSH_ASKPASS, then the terminal (unless disabled). If nothing yields an answer, the command stops with could not read Username for '<url>': terminal prompts disabled.
Edge cases: the variable only controls Git's own prompts. An ssh password or passphrase prompt is separate (use ssh -o BatchMode=yes, for example via GIT_SSH_COMMAND). A credential helper can still prompt on its own, for instance a GUI helper opening a window.
Usage notes
- Always set it in automation. A CI job that hits an expired token should fail in seconds with a readable error, not time out after an hour.
GIT_ASKPASSreceives text likeUsername for 'https://example.com':and should print only the answer. It is the usual way to inject a token from a secrets store, but prefer a credential helper if one fits, since askpass programs are called for every question.- The password prompt includes the user name already answered (the second example printed
Password for 'https://[email protected]':because its script answeredx), so one askpass script can answer both questions by matching on the start of the text. - Not a security feature. Disabling prompts does not stop a helper from using stored credentials, and it does not hide URLs containing embedded passwords.
- Related fail-fast settings:
GIT_SSH_COMMAND="ssh -o BatchMode=yes"for ssh, andGIT_HTTP_LOW_SPEED_LIMITwithGIT_HTTP_LOW_SPEED_TIMEfor stalled HTTP transfers.
Related
git credential,credential.*,GIT_SSH_COMMAND,http.*- Lessons: Remotes, Troubleshooting