GitHub 邮箱隐私配置与 GH007 错误解决
一、GitHub 多邮箱机制
| 邮箱类型 | 作用 | 典型场景 |
|---|---|---|
| 主邮箱 (Primary) | 登录、接收通知、找回密码 | 注册时的第一个邮箱 |
| 备用邮箱 | Git 提交作者身份、保护隐私 | 后来绑定的邮箱 |
二、查看与验证邮箱
1. 打开 github.com/settings/emails
2. 带 Primary 标签的是主邮箱
3. 未验证的邮箱需点击 Resend verification
三、Git 提交邮箱设置
git config --global user.email "你的邮箱@example.com"
四、GH007 错误:隐私保护拦截
推送时若遇到:
> remote: error: GH007: Your push would publish a private email address.
原因
使用了未验证或被 GitHub 标记为私密的邮箱。推荐方案:使用 GitHub noreply 邮箱
1. 打开 github.com/settings/emails
2. 找到 Keep my email addresses private
3. 复制 noreply 邮箱,如 用户名@users.noreply.github.com
4. 重新配置:
git config --global user.email "你的noreply邮箱@users.noreply.github.com"
git commit --amend --author="用户名 <你的noreply邮箱@users.noreply.github.com>" --no-edit
git push
备选方案:关闭隐私保护
1. 打开 github.com/settings/emails
2. 取消勾选 "Keep my email addresses private"
3. 重新 git push
五、修改已提交但未推送的邮箱
git commit --amend --author="正确用户名 <正确邮箱>" --no-edit
git push
若已 push,需强制覆盖(个人项目可用):
git push --force-with-lease
六、总结流程
设置 Git 身份 → 修改代码 → git add → git commit → 处理邮箱隐私 → git push
首次配置完成后,日常只需 add → commit → push 三步。