fatal: could not read Username for 'https://github.com': terminal prompts disabled — the server asked for credentials, Git had none it could use, and GIT_TERMINAL_PROMPT=0 forbade it to ask you. Check the URL first, because GitHub asks for credentials for a repository that does not exist too. If the URL is right, give Git a credential it can use without asking: a token in CI, the credential manager on your own PC, or SSH.

This is the error of jobs nobody is watching: CI runners, scheduled scripts, build tools that run Git for you.

The error

PS> $env:GIT_TERMINAL_PROMPT = "0"
PS> git clone https://github.com/fix6-no-such-org-7c1e/private-repo.git
Cloning into 'private-repo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled

Exit code 128, and no folder was left behind.

Why it happens

When an HTTPS remote answers 401, Git asks its credential helpers for a username and password, and if none answers, it asks at the terminal. GIT_TERMINAL_PROMPT=0 switches that last step off, so a job without a person cannot hang forever waiting for input. Git exits instead and names the host it wanted a username for.

A header trace of the clone above (GIT_TRACE_CURL) shows why the URL matters. The repository does not exist, yet GitHub answered the anonymous request with HTTP/1.1 401 Unauthorized and www-authenticate: Basic realm="GitHub", not with "not found". To a client without credentials, a typo in the owner name looks the same as a private repository. Tools that run Git on your behalf often set GIT_TERMINAL_PROMPT=0 themselves, which is why the line usually appears in a build log rather than in your own terminal.

The fix

A local server that demands credentials the way GitHub does gave the same line without one:

PS> git clone http://127.0.0.1:15901/private-repo.git
Cloning into 'private-repo'...
fatal: could not read Username for 'http://127.0.0.1:15901': terminal prompts disabled

With a token from an environment variable, passed as a header for this one command, it worked:

PS> $basic = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("ci-bot:$env:GIT_TOKEN"))
PS> git -c http.extraHeader="Authorization: Basic $basic" clone http://127.0.0.1:15901/private-repo.git
Cloning into 'private-repo'...
PS> git -C private-repo log --oneline
15e70c4 Add README

The -c setting lasts for one command: git -C private-repo config --get-all http.extraHeader returned nothing afterwards, so the clone keeps no secret. A wrong token gave the same "could not read Username" line, so an expired token looks exactly like a missing one. For GitHub, the token is a personal access token, or the token your CI system provides, with read access to that repository.

On your own PC, Git for Windows ships Git Credential Manager (git credential-manager --version printed 2.5.0 here). With credential.helper set to manager, the first HTTPS clone opens a sign-in instead of failing, and later commands reuse what was stored; this test did not sign in. SSH remotes (git@github.com:owner/repo.git) authenticate with a key and never ask for a username; that route was not tested here.

How it was reproduced

Git for Windows 2.45.2 (git version 2.45.2.windows.1) from Windows PowerShell 5.1. The personal global config, which sets credential.helper to manager, was replaced by an empty file (GIT_CONFIG_GLOBAL), so no helper ran, as on a bare CI runner. One anonymous clone of a repository that does not exist on github.com produced the error. The fix was confirmed against a small Python server on 127.0.0.1 that wraps git-http-backend and answers 401 unless the request carries the test token. The names fix6-no-such-org-7c1e and ci-bot are the test's own.

Frequently asked

What does 'terminal prompts disabled' mean in Git?
GIT_TERMINAL_PROMPT is set to 0, so Git may not ask for a username or password at the terminal. When the server wants credentials and no credential helper supplies them, Git stops with this message instead of waiting.
Why does Git ask for a username for a repository that does not exist?
GitHub answered an anonymous request for a missing repository with 401 and a request for credentials, not with not found. Check the owner and repository name in the URL before looking for a token problem.
How do I clone a private repository in CI without a prompt?
Give Git a credential it can use without asking: a token passed with git -c http.extraHeader for that command, the token your CI system provides, or an SSH deploy key. The token needs read access to the repository.

More decoded errors in the Fixes category. Remotes, HTTPS and SSH keys are explained in Part 6 of the Git series, GitHub: Your Code in the Cloud.