Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~5 min readGit
#git#credentials#ci#https
Bold white headline reading NO PROMPT beside a cyan git crate holding an amber blank credential slot.

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.

bash
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 anywhere

Git 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.

bash
# 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 address

Reproduce the CI behaviour locally:

bash
GIT_TERMINAL_PROMPT=0 git -c credential.helper= fetch origin # fatal: could not read Username for 'https://github.com': terminal prompts disabled
Credential sourceConfigured bySurvives rebootWorks with 2FA
URL userinfo https://user:token@host/repothe clone URLif storedyes, token
credential.helper=store~/.git-credentials plaintextyesyes, token
credential.helper=cachein-memory daemonuntil timeoutyes
Git Credential ManagerOS keychainyesyes, OAuth
git config http.extraHeaderper command or confignoyes, token
SSH key~/.ssh/config, agentyesn/a
SituationPrompt is disabled becauseCorrect fix
GitHub Actions, GitLab CIno TTY by designtoken in URL or header, or actions/checkout with token
cron or systemd timerno terminal attachedcredential helper with a token file
Docker buildnon-interactive layer--secret mount, not ARG
VS Code or JetBrains git panelgit spawned without a consoleconfigure a helper once per user
SSH agent forwarding offHTTPS remote used anywaygit remote set-url to SSH
Expired token in helperstored secret is staleclear the helper entry, re-authenticate

Key Comparison Table

MethodCommandRisk
Token in remote URLgit remote set-url origin https://x-access-token:$TOKEN@github.com/acme/api.gittoken leaks into .git/config and CI logs
Header per commandgit -c http.extraHeader="Authorization: Basic <base64 of user:token>" fetchcommand history
Credential helper, envgit config --local credential.helper '!f() { echo "username=x-access-token"; echo "password=$GH_TOKEN"; }; f'shell quoting
Askpass scriptGIT_ASKPASS=/usr/local/bin/askpass git fetchscript must be executable
SSH keygit remote set-url origin git@github.com:acme/api.gitkey management, host verification
insteadOf rewritegit config --global url."git@github.com:".insteadOf "https://github.com/"surprising for other repos
Error textMeaningNext step
could not read Username ... terminal prompts disabledno credentials and no TTYadd a helper or token
could not read Password ... terminal prompts disabledusername supplied, password missinghelper holds only the username
Authentication failed for 'https://...'credentials sent and rejectedcheck token scopes and expiry
Repository not foundprivate repo without access, or renamedcheck access and the URL
Support for password authentication was removedaccount password used instead of tokencreate a PAT
Permission denied (publickey)SSH key not acceptedcheck ssh -T git@github.com
Host key verification failedunknown host key in a fresh imagessh-keyscan with verification

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Why the prompt cannot appear

bash
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 error

Git 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

bash
git config --global credential.helper store printf 'protocol=https\nhost=github.com\nusername=x-access-token\npassword=%s\n\n' "$GH_TOKEN" | git credential approve

store 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:

bash
printf 'protocol=https\nhost=github.com\n\n' | git credential reject

3. CI without leaking the token

- uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} persist-credentials: false
bash
git -c http.extraHeader="Authorization: Bearer $GITHUB_TOKEN" fetch

A 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:

dockerfile
RUN --mount=type=secret,id=netrc git clone https://github.com/acme/private.git /src

4. SSH instead of HTTPS

bash
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.git

SSH 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 -5

A 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

bash
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 in git remote -v output. Rotate immediately if it was pushed anywhere.
  • credential.helper with 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.git and https://github.com/acme/api.git are different remotes with different auth paths.
  • Relying on store in a container. The file is written under $HOME; a different HOME in 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=never so 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.helper handling for system installs, and newer Git versions honour credential.https://github.com.helper overrides 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 documentation

The Git documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Git guides

More in Git

All Git guides

The guides filed next to this one in Git, in library order.