397

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 'git@github.com: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?

Brad Schoening
  • 1,281
  • 6
  • 22
Franck Freiburger
  • 26,310
  • 20
  • 70
  • 95
  • 1
    I found the documentation page: https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address – Sebastian Norr Nov 26 '19 at 10:26
  • The canonical (self-contained) answer is [Winfried's to *Your push would publish a private email address error*](https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error/51097104#51097104) – Peter Mortensen Jun 29 '20 at 15:45
  • I wonder if anyone could show how to locate the email exposure in the commit. – Eduardo Reis Apr 15 '21 at 18:13
  • Never mind, after doing a grep command in my repository `grep -R @gmail. .` and reading this [other page](https://www.meziantou.net/hide-your-email-address-on-github.htm), 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. – Eduardo Reis Apr 15 '21 at 18:21

7 Answers7

833

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
    
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
  • 1
    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`. – adamczi Aug 08 '17 at 21:35
  • 9
    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. – Ioanna Aug 23 '17 at 12:39
  • 6
    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 `@users.noreply.github.com` (like myself setting to `None`) will result in not showing your commits in the graph on your profile page. – adamczi Aug 23 '17 at 15:21
  • 3
    I had a similar mysterious problem. My mistake was to `git commit --amend --author "first last me@users.noreply.github.com"` and it didn't seem to like that. You _really_ need to reset the `user.email` configuration parameter exactly as above. Cheers! – msanford Aug 25 '17 at 14:40
  • 2
    I had to deselect and reselect the "Keep my email address private" option before github would display my noreply email address. See here: https://help.github.com/articles/about-commit-email-addresses/ – craq Oct 03 '17 at 04:34
  • 7
    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. – teaman Nov 08 '17 at 19:18
  • 5
    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 repository](https://help.github.com/en/articles/setting-your-commit-email-address-in-git#setting-your-email-address-for-a-single-repository) – gfullam Apr 15 '19 at 14:52
  • 1
    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. – Mary Ellen Bench Dec 25 '19 at 23:45
  • 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. – Andrew Jan 13 '20 at 14:23
  • 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. – Ian Mar 13 '21 at 19:00
  • 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. – Shane Halloran Jul 03 '21 at 17:45
  • 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. :-) – Henke Apr 14 '22 at 13:31
  • When I try , says "$ git commit --amend --reset-author fatal: this operation must be run in a work tree" – Andrew Truckle May 19 '22 at 22:14
  • 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? – superboot Feb 21 '23 at 22:57
  • 1
    Resetting the author was the most important bit for me, thanks! – Pedro Silva Jun 15 '23 at 13:08
162

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.

Jordan Lewis
  • 16,900
  • 4
  • 29
  • 46
  • 24
    do unchecking this option will expose my private email address ? – Franck Freiburger Apr 12 '17 at 19:39
  • 16
    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. – Lasse V. Karlsen Apr 12 '17 at 19:40
  • 19
    This is a questionable solution. At least mention that this will expose your email address to the whole world. – kovac Jan 12 '20 at 04:42
  • [Daniel A.A. Pelsmaeker's](https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions/44099011#44099011) and [Winfried's](https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error/51097104#51097104) are the better answers. – Peter Mortensen Jun 29 '20 at 15:47
18
  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
Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
17

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.

34661293+aslancan32@users.noreply.github.com 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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
maslancan
  • 399
  • 2
  • 5
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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anjani Barnwal
  • 1,362
  • 1
  • 17
  • 23
  • 6
    this will work but it will expose your private email address. if you're concerned about privacy see other solutions. – kaznovac Apr 11 '20 at 12:14
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 "myemail@domain.com"

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

Using Github Desktop fixed my issue.

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42