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

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

如果使用GitHub Desktop軟件提交可能會(huì)報(bào)以下錯(cuò)誤

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,可能會(huì)出現(xiàn)以下錯(cuò)誤

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選項(xiàng),允許你的私人郵箱也可以推送,但是可能還是會(huì)暴露你的郵箱。

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

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

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

如果還不會(huì)給 Git 設(shè)置多個(gè)SSH-Key,請(qǐng)參考Git 配置多個(gè) 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

目前還是比較推薦第三種方法的,對(duì)于多 Git 賬號(hào)的人,可以只在~/.ssh/config添加User user即可推送。親測(cè)可用。

參考資料

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

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

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

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