报错信息:
Pushing to https://github.com/***.git POST git-receive-pack (1288 bytes) remote: error: GH007: Your push would publish a private email address. remote: You can make your email public or disable this protection by visiting: remote: http://github.com/settings/emails To https://github.com/***.git ! [remote rejected] master -> master (push declined due to email privacy restrictions) error: failed to push some refs to 'https://github.com/***.git'
出现报错的场景:
由于使用公司电脑,设置了global的全局git账号。我在自己的github仓库,修改了name和email,然后就push不了了。
解决方法:
网上还有一种方法:
Open your GitHub account, and go to Settings > Emails.
Select the Keep my email address private check box.
就是将email的私有设置为公开,可我就是不想公开,便找到如下解决方案。
-
如果也是配置了name和email,则先确认仓库的.git 中的config的是否正确:
git config user.name "{name}"
【就是github中Public profile下的Name】
git config user.email "{username}@users.noreply.github.com"
【就是github中点击头像,Signed in as 后面的那个名字,也是生成代码路径中标识的那个名字】
其实,这个用户名和邮箱,也是第一次检出代码时那个。 -
跳出后.git文件夹,在仓库文件夹下,输入命令行:
git commit --amend --reset-author
esc
:wq
然后使用sourceTree就push成功了。
解决方法参考:
https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error