Git "Authentication failed for ..." with a Token in CI
By Daniel Zoghalchali·Latchkey
A token was supplied but the host still rejected authentication. The token itself is the problem - expired, revoked, not granted this repository, or not SSO-authorized for the org.
What this error means
An HTTPS operation that passes a token fails with fatal: Authentication failed for 'https://github.com/org/repo.git/'. The same token may work on a different repo or org, which points at scope/expiry rather than a typo.
git output
remote: Invalid username or token. Password authentication is not supported
for Git operations.
fatal: Authentication failed for 'https://github.com/org/repo.git/'
Diagnose it: depth, refs, or credentials?
Terminal
git rev-parse --is-shallow-repository
git rev-parse --abbrev-ref HEAD # prints HEAD when detached
git log --oneline -3
git remote -v
Common causes
Expired or revoked token
A PAT or installation token that lapsed or was rotated authenticates no more. The workflow starts failing with no code change.
Fine-grained token missing this repository
A fine-grained PAT scoped to specific repos cannot authenticate against one outside its access list, so even a read fails.
SSO not authorized for the PAT
For an org with SAML SSO, a classic PAT must be explicitly authorized for that org. An unauthorized PAT is rejected even with correct scopes.
How to fix it
Rotate and re-store the token
Confirm the token is current - not expired or revoked.
Regenerate it with the required scopes/permissions and update the CI secret.
For SAML orgs, authorize the PAT for SSO in the token settings.
Scope the token to this repository
For a fine-grained PAT, add the target repo to its repository access; for an App, confirm the installation covers it.
Terminal
git ls-remote https://x-access-token:${GITHUB_TOKEN}@github.com/org/repo.git
# success here proves the token can see the repo
How to prevent it
Prefer short-lived App/installation tokens or OIDC over long-lived PATs.
Track token expiry and rotate before it lapses.
Authorize PATs for SSO orgs and scope fine-grained tokens to the right repos.
Frequently asked questions
What causes Git "Authentication failed for ..." with a token in CI?
There are 3 common causes: expired or revoked token, fine-grained token missing this repository, and sso not authorized for the pat. A PAT or installation token that lapsed or was rotated authenticates no more.
How do I fix Git "Authentication failed for ..." with a token in CI?
There are 2 fixes depending on which cause you have: rotate and re-store the token and scope the token to this repository. Work through them in order, since the first is the most common.
What does Git "Authentication failed for ..." with a token in CI actually mean?
An HTTPS operation that passes a token fails with fatal: Authentication failed for 'https://github.com/org/repo.git/'.
How do I stop Git "Authentication failed for ..." with a token in CI happening again?
Prefer short-lived App/installation tokens or OIDC over long-lived PATs. The prevention section lists 3 changes that keep it from recurring.