一、修改 GitHub 用户名(username)
1. 网页修改(推荐)
- 登录 https://github.com
- 点击右上角头像 → Settings
- 左侧栏选择 Account
- 找到 Change username → 输入新用户名 → Update username
修改用户名不会丢失代码仓库,但旧的
https://github.com/oldname/repo.git会自动重定向;建议更新本地仓库的远程地址。
2. 更新本地仓库的远程地址
如果你之前使用:
https://github.com/oldname/myrepo.git
修改后执行:
git remote set-url origin https://github.com/newname/myrepo.git
查看是否成功:
git remote -v
二、修改 GitHub 密码(或令牌)
GitHub 2021 年起已不再支持密码推送代码,推送需要使用 Personal Access Token (PAT)。
1. 修改 GitHub 登录密码(网页)
- 登录 GitHub → 点击头像 → Settings
- 左侧选择 Password and authentication
- 在 Change password 部分输入旧密码和新密码。
2. 修改 Git 推送认证方式(命令行)
如果你用 HTTPS 推送
旧版本可能还保存了密码,现在要改成使用 Token。
- 先生成新 Token
- 进入 https://github.com/settings/tokens
- 点击 Generate new token → classic
- 勾选权限:
repo、read:org、workflow(视情况) - 复制生成的 Token
- Username: 你的 GitHub 用户名
- Password: 粘贴刚才的 Token
再次执行推送:
git push origin main
会提示输入用户名和密码,此时在本地仓库中更新凭证:
git credential-cache exit
git credential reject https://github.com
如果你使用 SSH 推送
检查 .ssh/config,或重新生成公钥:


