本地github ssh多账号问题

哈哈,看来你的 老账号 xxxxx 还在"阴魂不散" ,而且你现在用的是 HTTPS 方式 而不是 SSH,所以 SSH 配置对它无效!

别急,我们有两种方法解决:


🔧 解决方案 1:改用 SSH 方式(推荐)

既然你已经配好了 SSH 多账号,那就直接 把远程仓库地址从 HTTPS 改成 SSH

  1. 查看当前远程地址(确认是 HTTPS):

    bash 复制代码
    git remote -v

    输出可能是:

    复制代码
    origin  https://github.com/xxxxxxxx/xxx.git (fetch)
    origin  https://github.com/xxxxxxxx/xxx.git (push)
  2. 修改为 SSH 地址 (用你 ~/.ssh/config 里定义的 Host):

    bash 复制代码
    git remote set-url origin git@github.com-newaccount:xxxxxxxxx/elm.git

    (⚠️ github.com-newaccount 要和你 ~/.ssh/config 里的 Host 名一致!)

  3. 再 push 试试

    bash 复制代码
    git push origin main

    ✅ 现在应该不会报 xxxxxxx 的权限问题了!


🔧 解决方案 2:清除 Git 的 HTTPS 认证缓存(如果仍想用 HTTPS)

如果你 非要继续用 HTTPS,那就得清除 Git 的旧账号缓存:

Windows(Git Credential Manager)

  1. 打开 Windows 凭据管理器(Win + S → 搜索"凭据管理器")。
  2. 进入 Windows 凭据 → 普通凭据
  3. 找到 git:https://github.com 相关的条目,删除它

Mac / Linux(Git 凭据缓存)

运行:

bash 复制代码
git config --global --unset credential.helper

或者手动清除缓存:

bash 复制代码
git credential reject <<EOF
protocol=https
host=github.com
EOF

然后重新 push,会弹出 GitHub 登录窗口

这时输入 新账号的用户名和密码(或 Personal Access Token) 即可。


💡 终极建议:尽量用 SSH!

  • HTTPS 每次 push 都可能要输密码(除非存了 PAT)。
  • SSH 配置好后 一劳永逸,还能多账号切换。

🚀 现在再试试 git push,应该没问题了吧?

如果还不行,请提供:

  1. git remote -v 的输出
  2. cat ~/.ssh/config 的内容
  3. 你用的 Git 版本(git --version

我来帮你 精准"捉鬼"!👻🔫

相关推荐
网硕互联的小客服1 小时前
各个版本的Linux系统如何修改远程端口ssh端口?
linux·运维·服务器·网络
AlfredZhao1 小时前
GitHub 克隆他人私有仓库:从授权到下载
github
智能制造产品经理代码提升1 小时前
Windows Git 多 GitHub 账号切换(GCM 管理凭据,不覆盖原有账号)
github
Wang's Blog2 小时前
Java框架快速入门: Spring Security+OAuth2之核心角色与授权流程
java·spring·github
dong_junshuai2 小时前
每天一个开源项目#100 OpenCodeReview:2.6万星的低噪声AI审查器
程序员·开源·github
峰向AI3 小时前
还在用 Ableton?这个 3.5K Star 的免费音序器,让你在手机上写微分音音乐
github
Mr小林3 小时前
Docker 安装教程(在线 + 离线)
运维·docker·容器
SL_staff3 小时前
战略落地的最后一公里:从目标到个人日历的自动化链路实现
java·github·全栈
JudithHuang3 小时前
把本地服务暴露到公网
运维
凌奕4 小时前
OpenCodeReview 架构拆解:AI Code Review 为什么不能只是 Git Diff + LLM?
llm·github·agent