美文网首页
解决启用GitHub隐私邮箱后推送错误的问题

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

作者: 曾經蠟筆沒有小新 | 来源:发表于2024-08-08 02:49 被阅读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 中设置全局邮箱。使用 GitHub 提供的隐私邮箱。
      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

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/ffpckjtx.html