fatal: could not read Username for github.com: Fix
Last updated
fatal: could not read Username for 'https://github.com' means git tried to fetch something over HTTPS, was asked for credentials, and had none to give. In a workflow there is no terminal to type in, so git gives up. The usual trigger is a private repository: a private submodule, a private package installed from a git URL, or a second repository you check out. The built-in GITHUB_TOKEN only covers the repository the workflow runs in.
The exact message
fatal: could not read Username for 'https://github.com': No such device or address
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Both forms mean the same thing. A related message for SSH remotes is Permission denied (publickey).
Fix 1: check out a second private repository with a token
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: my-org/private-lib
path: private-lib
token: ${{ secrets.CROSS_REPO_TOKEN }}
CROSS_REPO_TOKEN should be a fine-grained personal access token or a GitHub App installation token with read access to Contents on that one repository. Create a token for the smallest set of repositories you need.
Fix 2: private submodules
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.CROSS_REPO_TOKEN }}
The token you pass is used for the submodule fetches as well. If the .gitmodules file uses SSH URLs, either switch them to HTTPS or use an SSH key (see the publickey page).
Fix 3: dependencies installed from git URLs
npm install, pip install git+https://..., go get and Cargo git dependencies all run git themselves. Tell git to use the token for every GitHub HTTPS URL before the install step:
- name: Let git use a token for private GitHub dependencies
run: git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"
env:
GH_TOKEN: ${{ secrets.CROSS_REPO_TOKEN }}
- run: npm ci
For Go, also set GOPRIVATE=github.com/my-org/* so the Go proxy is not asked for private modules. The runner is a fresh machine for hosted runners, so this setting is gone after the job. On a self-hosted runner that is reused, use git config --local or unset it afterwards so the token does not stay on disk.
Fix 4: the token is set but does not have access
If you already pass a token, check that it has not expired, that it was created for the right organisation, and that organisation SSO is authorised for it if the organisation requires that. A token with the right scope but no access to the specific repository gives the same family of errors, sometimes as Repository not found.
Fix 5: the repository name is wrong
A typo in repository: produces a failure that looks like an authentication problem, because GitHub does not reveal whether a private repository exists.
How to prevent it
- Use a GitHub App token or a fine-grained token limited to the repositories the workflow needs.
- Put cross-repository access in one documented secret, and set an expiry reminder.
- Prefer HTTPS plus a token in CI over SSH, unless you have a deploy key set up.
- Avoid private git dependencies where a package registry would do.
- Never print the token. Secrets are masked in logs, but a URL built with it in a debug line can still leak in other forms.
FAQ
Why does my GITHUB_TOKEN not work for another repository?
The GITHUB_TOKEN is scoped to the repository running the workflow. Access to any other private repository needs a different token.
Does this error mean my token is wrong?
It means no credential was supplied for that URL. If a wrong token were used you would usually see a 403 or Authentication failed instead.
Do I need a personal access token?
Not necessarily. A GitHub App installation token is better for teams because it is not tied to one person's account.
Does it happen on public repositories?
Not for cloning them. It can appear if the URL points at a repository that was renamed, made private or deleted.
Related
- Cache Service Responded With 429: FixFix "Failed to restore: Cache service responded with 429" in GitHub Actions: too many cache requests. Upgrade actions/cache, restore once, save once.
- Invalid Workflow File: YAML Syntax Error FixFix "Invalid workflow file" and "You have an error in your yaml syntax" in GitHub Actions: indentation, unexpected value, bad expressions, with actionlint.
- JavaScript Heap Out of Memory in GitHub Actions: FixFix "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory" and npm ENOMEM in GitHub Actions with NODE_OPTIONS.
- Permission Denied (publickey) in GitHub Actions: FixFix "git@github.com: Permission denied (publickey)" in GitHub Actions: add an SSH key or deploy key, or switch to an HTTPS token for private repos.