【踩坑】Git推送到Github时报错

前言

Git推送到Github时报错:push declined due to email privacy restrictions

原因

  • Github账户开启了Keep my email addresses privateBlock command line pushes that expose my email来保护隐私后,推送到Github时,如果提交代码的邮箱是登录账户邮箱,会被拒绝提交

解决问题

  • 关闭Block command line pushes that expose my email隐私保护,或者Undo Commit后,修改提交代码的邮箱(改为Github转发邮箱),再重新提交,然后推送

<id><username>@users.noreply.github.com:Github转发邮箱

1
2
git config --global user.email <id><username>@users.noreply.github.com
git config user.email <id><username>@users.noreply.github.com

完成

参考文献

stackoverflow——Daniel A.A. Pelsmaeker