解决启用GitHub隐私邮箱后推送错误的问题

2024-08-08  本文已影响0人  曾經蠟筆沒有小新

解决启用 GitHub 隐私邮箱后推送错误的问题

如果使用GitHub Desktop软件提交可能会报以下错误

fatal: unable to access 'https://github.com/username/project.git/': Failed to connect to github.com port 443 after 75003 ms: Couldn't connect to server


如果使用终端iTerm2,可能会出现以下错误

Cannot push these commits as they contain an email address marked as private on GitHub. To push anyway, visit https://github.com/settings/emails, uncheck "Keep my email address private", then switch back to GitHub Desktop to push your commits. You can then enable the setting again.

如果你已经设置了隐私邮箱,并且已经使用了,但是还是无法提交

  1. 取消勾选Block command line pushes that expose my email选项,允许你的私人邮箱也可以推送,但是可能还是会暴露你的邮箱。

  2. 如果想继续使用隐私邮箱,在 Settings → Emails中,保持勾选Keep my email addresses privateBlock command line pushes that expose my email选项,

找到你的 GitHub 隐私邮箱,它在Keep my email addresses private的描述中。

保持勾选
  git config --global user.email "{ID}+{username}@users.noreply.github.com"
  git config user.email "{ID}+{username}@users.noreply.github.com"
git commit --amend --reset-author --no-edit
  1. 当有多个 Git 账号时,并设置了多个SSH-Key,在~/.ssh目录下找到config文件,并在每个 Host 下,添加User {ID}+{username}@users.noreply.github.com

如果还不会给 Git 设置多个SSH-Key,请参考Git 配置多个 SSH-Key

Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
User {ID}+{username}@users.noreply.gitee.com

Host github.com
Hostname ssh.github.com
Port 443
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
User {ID}+{username}@users.noreply.github.com

目前还是比较推荐第三种方法的,对于多 Git 账号的人,可以只在~/.ssh/config添加User user即可推送。亲测可用。

参考资料

Error "Your push would publish a private email address"
How to amend several commits in Git to change author
Git 配置多个 SSH-Key

上一篇 下一篇

猜你喜欢

热点阅读