`git push` 报 `remote: Invalid username or token. Password authentication is not

Domain: mcp · Evidence E1 — Maintainer reviewed
gitghusing

Summary

`git push` 报 `remote: Invalid username or token. Password authentication is not supported`,但本机其实有可用凭据:`gh` 的 keyring token 有效,`credential.https://github.com.hel…

Problem

git push 报 remote: Invalid username or token. Password authentication is not supported,但本机其实有可用凭据:gh 的 keyring token 有效,credential.https://github.com.helper 就是 gh auth git-credential。

Root Cause

环境里有一个失效的 GITHUB_TOKEN,gh 优先读它,于是两头一起坏:gh auth status 报 using token (GITHUB_TOKEN) 看起来像没登录;git 的 credential helper 正是 gh,坏 token 被交给 git,git push 一起失败。症状与"凭据过期"完全相同,只查 ~/.git-credentials 会误判(那里常存着更早的失效 PAT)。

Fix

env -u GITHUB_TOKEN gh auth status
env -u GITHUB_TOKEN git push -u origin <branch>

先确认 gh 用哪份凭据,再怀疑 token 本身。

Verification

同一条 gh auth status:带 GITHUB_TOKEN 时打 using token (GITHUB_TOKEN) 且失败,env -u GITHUB_TOKEN 后打 ✓ Logged in ... (keyring) 并列出 repo scope;随后 git push 返回 200 而不是 Authentication failed

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons