命令行里主要切两处:gh 登录账号,以及 Git 推送用的凭据。

查看当前账号:

gh auth status
git credential-manager github list

切换到已登录过的 gh 账号:

gh auth switch --hostname github.com --user 【账号名】

如果还没登录该账号:

gh auth login --hostname github.com --git-protocol https --web

如果只想让当前项目用某个账号推送,可以在项目目录执行:

git config credential.https://github.com.helper manager
git config credential.https://github.com.username 【账号名】

如果要重新添加 Git Credential Manager 里的账号:

git credential-manager github login --username 【账号名】 --browser --force

如果要删除旧账号,例如 myaccount:

git credential-manager github logout 【账号名】

以后推送失败时,先查这几个值最直接:

gh auth status
git config --get credential.https://github.com.username
git config --get http.proxy
git remote -v
Logo

免费领 200 小时云算力,进群参与显卡、AI PC 幸运抽奖

更多推荐