Git: could not read Username, terminal prompts disabled
A headless git has no terminal to ask for credentials. Supply a token through a helper, a header or SSH instead of relying on a prompt.

Introduction & Quick Summary
A build runner fails on the first fetch:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Quick answer: git needs credentials for an HTTPS remote, tried to ask for a username, and found no terminal to ask on. Nothing is wrong with the repository; the environment simply has no way to answer a prompt.
git remote -v
# origin https://github.com/acme/api.git (fetch)
git config --get credential.helper
# (empty)
GIT_TERMINAL_PROMPT=0 git ls-remote origin # reproduces the message anywhereGit asks for a username only in the HTTP transport, and only when the server returned 401. In a terminal you would type it; in CI, cron, a systemd unit, a Docker build or an editor's git panel there is no TTY, so git aborts. The fix is to supply credentials non-interactively: a credential helper with a token, a token in the URL, an SSH key, or an askpass program. This guide covers each option, the CI-safe form of each, and the failures that look identical but need a different fix.
Core Mechanics, Signatures & Reproducible Setup
The HTTP transport follows this order: check the URL for a userinfo part, ask the configured credential helper, then prompt on the terminal. GIT_TERMINAL_PROMPT=0 disables the last step, and Git Credential Manager does the same when GCM_INTERACTIVE=never is set.
# no helper, no TTY
env -u DISPLAY GIT_TERMINAL_PROMPT=1 git clone https://github.com/acme/private.git
# fatal: could not read Username for 'https://github.com': No such device or addressReproduce the CI behaviour locally:
GIT_TERMINAL_PROMPT=0 git -c credential.helper= fetch origin
# fatal: could not read Username for 'https://github.com': terminal prompts disabled| Credential source | Configured by | Survives reboot | Works with 2FA |
|---|---|---|---|
URL userinfo https://user:token@host/repo | the clone URL | if stored | yes, token |
credential.helper=store | ~/.git-credentials plaintext | yes | yes, token |
credential.helper=cache | in-memory daemon | until timeout | yes |
| Git Credential Manager | OS keychain | yes | yes, OAuth |
git config http.extraHeader | per command or config | no | yes, token |
| SSH key | ~/.ssh/config, agent | yes | n/a |
| Situation | Prompt is disabled because | Correct fix |
|---|---|---|
| GitHub Actions, GitLab CI | no TTY by design | token in URL or header, or actions/checkout with token |
| cron or systemd timer | no terminal attached | credential helper with a token file |
| Docker build | non-interactive layer | --secret mount, not ARG |
| VS Code or JetBrains git panel | git spawned without a console | configure a helper once per user |
| SSH agent forwarding off | HTTPS remote used anyway | git remote set-url to SSH |
| Expired token in helper | stored secret is stale | clear the helper entry, re-authenticate |
Key Comparison Table
| Method | Command | Risk |
|---|---|---|
| Token in remote URL | git remote set-url origin https://x-access-token:$TOKEN@github.com/acme/api.git | token leaks into .git/config and CI logs |
| Header per command | git -c http.extraHeader="Authorization: Basic <base64 of user:token>" fetch | command history |
| Credential helper, env | git config --local credential.helper '!f() { echo "username=x-access-token"; echo "password=$GH_TOKEN"; }; f' | shell quoting |
| Askpass script | GIT_ASKPASS=/usr/local/bin/askpass git fetch | script must be executable |
| SSH key | git remote set-url origin git@github.com:acme/api.git | key management, host verification |
insteadOf rewrite | git config --global url."git@github.com:".insteadOf "https://github.com/" | surprising for other repos |
| Error text | Meaning | Next step |
|---|---|---|
could not read Username ... terminal prompts disabled | no credentials and no TTY | add a helper or token |
could not read Password ... terminal prompts disabled | username supplied, password missing | helper holds only the username |
Authentication failed for 'https://...' | credentials sent and rejected | check token scopes and expiry |
Repository not found | private repo without access, or renamed | check access and the URL |
Support for password authentication was removed | account password used instead of token | create a PAT |
Permission denied (publickey) | SSH key not accepted | check ssh -T git@github.com |
Host key verification failed | unknown host key in a fresh image | ssh-keyscan with verification |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Why the prompt cannot appear
git fetch 2>&1 | cat # stdout is a pipe, but stdin is still a TTY
setsid git fetch </dev/null # no controlling terminal: reproduces the errorGit asks on /dev/tty rather than stdin, and setsid removes the controlling terminal, so this is the closest local reproduction of a CI agent. Setting GIT_TERMINAL_PROMPT=0 makes the failure explicit instead of hanging a job for twenty minutes.
2. A credential helper that works unattended
git config --global credential.helper store
printf 'protocol=https\nhost=github.com\nusername=x-access-token\npassword=%s\n\n' "$GH_TOKEN" | git credential approvestore writes the secret in plaintext to ~/.git-credentials. On a CI runner that is ephemeral and acceptable; on a shared machine prefer the OS keychain helper (manager on Windows, osxkeychain on macOS, libsecret on Linux). To remove a stale entry:
printf 'protocol=https\nhost=github.com\n\n' | git credential reject3. CI without leaking the token
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: falsegit -c http.extraHeader="Authorization: Bearer $GITHUB_TOKEN" fetchA token inside the clone URL is echoed by git remote -v, printed in set -x output and stored in .git/config. A header passed with -c lives only for that command. In Docker, pass the token as a BuildKit secret:
RUN git clone https://github.com/acme/private.git /src4. SSH instead of HTTPS
ssh -T git@github.com
# Hi acme! You've successfully authenticated, but GitHub does not provide shell access.
git remote set-url origin git@github.com:acme/api.gitSSH avoids the prompt entirely once the key is loaded. url.insteadOf rewrites every matching HTTPS URL, which helps in a container image with a read-only config, and surprises anyone who later expects HTTPS. Scope it with --local when possible. Use the environment file parser to check how the token variable is actually exported, and the base64 encoder when a service requires the Basic header form.
5. Credentials exist but access is refused
gh auth status
curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/acme/api | head -5A fine-grained token needs Contents: read for fetch and Contents: write for push, plus explicit repository selection. Organisation SSO is the other frequent cause: the token is valid but not authorised for the org, and the API returns 404 rather than 403 to avoid leaking repository existence. Classic tokens need the repo scope, and expired tokens fail the same way as missing ones.
6. Tracing the transport
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git fetch 2>&1 | grep -E "http|credential|401"The trace shows whether a helper ran, what it returned (the password is redacted), and the HTTP status. git config --show-origin --get-all credential.helper reveals a helper configured in /etc/gitconfig that overrides the user's expectation.
Common Compilation/Runtime Mistakes & Version Gotchas
- Committing the token. A URL with a token ends up in
.git/config, in shell history, in CI logs and ingit remote -voutput. Rotate immediately if it was pushed anywhere. credential.helperwith an empty value.git config credential.helper ""resets the list, which is the right move when an inherited helper is misbehaving, and the wrong move when it was the only source.- Assuming an SSH remote uses the same URL.
git@github.com:acme/api.gitandhttps://github.com/acme/api.gitare different remotes with different auth paths. - Relying on
storein a container. The file is written under$HOME; a differentHOMEin the next step of a pipeline means the credentials are not there. - Interactive OAuth in a headless job. Git Credential Manager opens a browser or device flow and blocks. Set
GCM_INTERACTIVE=neverso it fails fast. - Version notes. GitHub removed password authentication in August 2021; since then the password field requires a PAT. Git 2.34 changed the default of
credential.helperhandling for system installs, and newer Git versions honourcredential.https://github.com.helperoverrides that can silently win. - Host key changes. A rebuilt runner image without a known-hosts entry fails later at the SSH step with a host verification error, not with this message, which is why both checks belong in the same pipeline test.
Pick the mechanism that matches where the job runs: a keychain helper on a workstation, a token header or actions/checkout in CI, an SSH key in a long-lived image. Then verify with git ls-remote under the same environment that failed, because that command exercises the credential path without changing any files.
Official documentation: gitcredentials and Caching your GitHub credentials in Git.
Official references
primary documentationThe Git documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit: fatal: not a git repository (or any parent): .git
The command ran outside a working tree or the .git metadata is gone. Confirm the root, restore a deleted .git, and repair worktree pointers.
Git: fatal: Need to specify how to reconcile divergent branches
Git 2.34 and later refuse to guess between merge, rebase and fast-forward. Set pull.rebase or pull.ff once, and know what each strategy does to history.
Git: fatal: unable to auto-detect email address
A commit needs an author identity. Containers and fresh installs have no user.email, so Git guesses from the OS user and refuses to continue.
Git: The current branch has no upstream branch
The branch exists locally with no tracking configured. Set upstream once with push -u, or let push.autoSetupRemote do it on every new branch.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.