T4、Pycharm 改成 ssh 认证
遇到 GitHub 认证问题确实很烦人,尤其是 IDE 集成时出现账户冲突。
一、强制使用 GitHub 账户认证(绕过 JetBrains 账户干扰)
1、清除现有凭据
# 清除 Git 全局凭据
git config --global --unset credential.helper
# 手动删除凭据(根据系统)
# Windows: 控制面板 → 凭据管理器 → 删除 GitHub 相关条目
# macOS: 钥匙串访问 → 搜索 "github" 删除
# Linux: rm ~/.git-credentials
2、改用 SSH 协议(彻底避开 HTTP 认证)
git remote set-url origin git@github.com:yourname/repo.git
- 确保 ~/.ssh/id_ed25519.pub 公钥已添加到 GitHub SSH Keys
3、强制 Git 使用 GitHub 账户
在项目目录下执行:
git config user.email "your-github-email@example.com"
git config user.name "Your GitHub Username"
二、针对 JetBrains IDE 的专项修复
1、禁用内置的 Git 凭据缓存
- 进入 Settings → Version Control → Git
- 取消勾选 Use credential helper
2、重置 IDE 的 GitHub 绑定
- 关闭所有项目
- 删除
~/Library/Application Support/JetBrains/<IDE版本>/options/github.xml
(macOS)
或%APPDATA%\JetBrains\<IDE版本>\options\github.xml
(Windows)
3、使用官方 GitHub 插件
- 在插件市场安装 GitHub Copilot(官方维护,比内置集成更稳定)
三、核验 GitHub 账户状态
1、检查账号权限
- 访问 https://github.com/settings/tokens
- 确认没有过期的 PAT (Personal Access Token)
- 如有必要,生成新 Token 并勾选 repo 和 workflow 权限
2、验证 SSH 连接
ssh -T git@github.com
应返回 You've successfully authenticated 而非任何错误
四、终极解决方案(推荐)
配置全局 Git 强制使用 SSH:
git config --global url."git@github.com:".insteadOf "https://github.com/"
此后所有 https://github.com/... 的远程地址会自动转为 SSH 协议,完全避开 HTTP 认证流程。
故障树分析
现象 | 最可能原因 | 解决方案 |
---|---|---|
弹出 JetBrains 登录框 | IDE 劫持了 Git 认证 | 禁用 Settings → Version Control → Git → Use credential helper |
403 Forbidden 错误 | 使用了过期/错误的 Token | 生成新 PAT 并更新 git config --global credential.helper store |
反复要求输入密码 | 系统凭据缓存冲突 | 切换到 SSH 协议或执行 git credential-manager reject https://github.com |
选择最适合你工作流的方案即可。SSH 方式通常能一劳永逸解决问题。