解決啟用GitHub隱私郵箱后推送錯誤的問題

解決啟用 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,可能會出現(xiàn)以下錯誤

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.

如果你已經(jīng)設(shè)置了隱私郵箱,并且已經(jīng)使用了,但是還是無法提交

  1. 取消勾選Block command line pushes that expose my email選項,允許你的私人郵箱也可以推送,但是可能還是會暴露你的郵箱。

  2. 如果想繼續(xù)使用隱私郵箱,在 Settings → Emails中,保持勾選Keep my email addresses privateBlock command line pushes that expose my email選項,

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

保持勾選
  • 打開終端,在 Git 中設(shè)置全局郵箱。使用 GitHub 提供的隱私郵箱。
  git config --global user.email "{ID}+{username}@users.noreply.github.com"
  • 在單個倉庫中設(shè)置隱私郵箱。
  git config user.email "{ID}+{username}@users.noreply.github.com"
  • 重置上次提交的作者信息。
git commit --amend --reset-author --no-edit
  1. 當有多個 Git 賬號時,并設(shè)置了多個SSH-Key,在~/.ssh目錄下找到config文件,并在每個 Host 下,添加User {ID}+{username}@users.noreply.github.com。

如果還不會給 Git 設(shè)置多個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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容