Meaning of the GitHub message: push declined due to email privacy restrictions
Asked Answered
I

7

427

I have accepted and merged a pull request on GitHub, and now I cannot pull my commits any more.

The message is:

! [remote rejected] master -> master (push declined due to email privacy restrictions)
error: failed to push some refs to '[email protected]:FranckFreiburger/vue-resize-sensor.git'


git did not exit cleanly (exit code 1) (3838 ms @ 12/04/2017 21:23:11)

What should I do now?

Impletion answered 12/4, 2017 at 19:28 Comment(4)
I found the documentation page: help.github.com/en/github/…Hyperbaton
The canonical (self-contained) answer is Winfried's to Your push would publish a private email address errorRuckman
I wonder if anyone could show how to locate the email exposure in the commit.Syblesybley
Never mind, after doing a grep command in my repository grep -R @gmail. . and reading this other page, I was able to understand that is not that my code is exposing my emails, but the commits themselves. Though obvious, I hadn't realized that before.Syblesybley
T
917

The remote repository has been configured to disallow you pushing a commit that would reveal your personal e-mail address. For example in GitHub you have checked the Block command line pushes that expose my email checkbox to enable this.

Block command line pushes that expose my email

While you can of course uncheck that setting, it will expose your private e-mail address to everyone in the world, as author information is readable by anyone with access to your repository.

Instead, do this:

  1. You can see your personal e-mail address, which is used by default for your commits in Git:

    git config --global user.email
    
  2. Find your GitHub noreply address in your GitHub's Personal Settings → Emails. It's mentioned in the description of the Keep my email address private checkbox. Usually, it starts with a unique identifier, plus your username:

    {ID}+{username}@users.noreply.github.com
    

    Keep my email address private

  3. Change the global user e-mail address setting to be your GitHub noreply address:

    git config --global user.email {ID}+{username}@users.noreply.github.com
    
  4. Reset the author information on your last commit:

    git commit --amend --reset-author
    

    If you have multiple commits with your private e-mail address, see this answer.

  5. Now you can push the commit with the noreply e-mail address, and future commits will have the noreply e-mail address as well.

    git push
    
Tessietessier answered 21/5, 2017 at 16:8 Comment(16)
That would still notify me about my e-mail being exposed. What I also had to do is to set your email to none using git config --global user.email none.Saidel
Nope, it worked like a charm on my side, maybe you forgot a step, @adamczi. This should be the accepted answer, as it states both possible solutions.Soave
Thanks, guess I might have done an error in the step 2. Worth noticing is that you should explicitly follow @Virtlink's instructions there, because setting an e-mail to other than <your_uname>@users.noreply.github.com (like myself setting to None) will result in not showing your commits in the graph on your profile page.Saidel
I had a similar mysterious problem. My mistake was to git commit --amend --author "first last [email protected]" and it didn't seem to like that. You really need to reset the user.email configuration parameter exactly as above. Cheers!Meek
I had to deselect and reselect the "Keep my email address private" option before github would display my noreply email address. See here: help.github.com/articles/about-commit-email-addressesSouthbound
Step 4 that Virtlink provides above was critical for my getting past this error. I had set the user.email in the config to use my no-reply email address, but the Push command still returned the frustrating error about publishing a private email. Once I amended the commit I was trying to push, it then allowed the push.Valentino
You may only want to change the email address for a single repository. This answer was helpful, but I also had to refer to github's help article: Setting your email address for a single repositoryShepp
That amend was the key, and very confusing, which is omitted from Github's instructions for some reason, for any commits that occurred before setting the no-reply.Friarbird
Confirm this works changing email and resetting the author. - error message also suggests 'disabling this protection'. Not clear what 'this' means presumably unticking 'block command line pushes that expose my email' under email settings.Apologete
I had to "push without tags" as well in order to get github at accept it, even after jumping through the hoops to change the repo's email addy.Bathurst
For point 3, I needed to also change the user.email configuration for the local repository, not just global. Maybe it's because I'm using version control from PyCharm? git config user.email {ID}+{username}@users.noreply.github.com. Then it worked.Mcleroy
I deliberately skipped step 4 to see what would happen. After step 5 I got an error suggesting to run git push --set-upstream origin main, which I did. That seems to have worked just as fine. :-)Annamarieannamese
When I try , says "$ git commit --amend --reset-author fatal: this operation must be run in a work tree"Stearne
Is there a way to have this only effect repos that push to github? aka, have the general global email be my real email, and have repos created with the gh CLI tool have the no-reply address set?Holder
Resetting the author was the most important bit for me, thanks!Pelagic
Thanks. Step 4 didn't work for me though, I had to run git commit --amend --author="{ID}+{username}@users.noreply.github.com" --no-edit just leaving it here in case it helps anyoneFume
K
164

This is likely caused by a new GitHub setting that blocks command line pushes that expose your email address.

Try unchecking the "Block command line pushes that expose my email" box in your email settings and then pushing again.

Kursh answered 12/4, 2017 at 19:35 Comment(4)
do unchecking this option will expose my private email address ?Impletion
Yes, that's what it will do but you've already exposed your email address if you've pushed commits to your repository. Even though Github won't show your email address, if I clone your repository I can see them just the same, and that's what this new prevent-push thingy will prevent.Uncrown
This is a questionable solution. At least mention that this will expose your email address to the whole world.Nealey
Daniel A.A. Pelsmaeker's and Winfried's are the better answers.Ruckman
D
25
  1. Open Emails section of github.com. Visit https://github.com/settings/emails.
  2. Go to Keep my email addresses private section and note down your donotreply email id.
  3. Open git terminal and set your donotreply email id as your email id using following command:
git config --global user.email "<your_donotreply_email_id"
  1. Revert your recent local commits (with your private email) which are getting failed to be pushed into repository.
git reset --soft HEAD~1 
  1. Stage and push those commits
git add .
git commit –m "<commit_message>"
git push
Deictic answered 20/3, 2021 at 8:16 Comment(3)
Thanks this works for me - after doing step 4Sweetsop
Thanks! All other solutions were confusing but your one is straightforward and worked!! Thanks!!Accord
Thanks as well! Step 4 was the fix for me AFTER I changed the email based on previous answers. I assume the commit was pushed up with my personal email and that needed to be cleared out and the commit repushed.Baneful
J
22

There is 3 options you can use:

1. You could uncheck your Keep my email addresses private in your GitHub E-mail Settings.

2. If you want hide e-mail your repositories, GitHub provide a noreply e-mail address in GitHub e-mail settings

Because you have email privacy enabled, will be used for account-related notifications as well as password resets.

[email protected] will be used for web-based Git operations, e.g., edits and merges.

git config --global user.email "<your-noreply-github-email>"

3- Or you can use your public email or business email for your repositories. Like m****@business.com

git config --global user.email "<your-public-email>"

After apply to your setting I recommend run reset header code :

git reset --soft HEAD~1 

Try again to push your repository

Jessamine answered 16/8, 2021 at 9:12 Comment(0)
G
3
  1. Just go to github.com and click on your profile
  2. Go to settings
  3. Now click on the 'Email' on the left navigation panel
  4. And search for the field 'Keep my email addresses private'
  5. Please uncheck this option
  6. Now please check again and I think your problem is solved now.
Geoffreygeoffry answered 18/3, 2020 at 9:34 Comment(1)
this will work but it will expose your private email address. if you're concerned about privacy see other solutions.Alarice
O
3

I solved the errors by:

git config --global user.email ""

This just sets my email to blank (an empty string). I now set my email in individual projects with:

git config user.email "[email protected]"

Omidyar answered 19/3, 2020 at 10:16 Comment(0)
F
1

Using Github Desktop fixed my issue.

Flexion answered 28/9, 2020 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.