13

When I am trying to push my commits with GitHub Desktop it showing this error "Cannot push these commits as they contain an email address marked as private on GitHub"

Please help me how to fix this error

Yeadh
  • 131
  • 1
  • 5
  • 3
    Possible duplicate of [Meaning of the GitHub message: push declined due to email privacy restrictions](https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions) – osowskit Sep 14 '18 at 04:51
  • That solution worked for me – frederj Mar 08 '19 at 21:02
  • 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

7 Answers7

12

The other answers are fine for future commits, but don't help for prior commits that contain a public email address. If you want to keep your email private, then you should modify the prior commits instead of changing your settings. Use git cmd, like:

git commit --amend --author="ericraider33 <9611418+ericraider33@users.noreply.github.com>"

And fill in with auto-generated email address that GitHub provides to each user.

raider33
  • 1,633
  • 1
  • 19
  • 21
  • 1
    This is useful. But you are missing the leading "<" before the email address, i.e. it should be <9611418+ericraider33@users.noreply.github.com> – arcdale Mar 23 '20 at 08:02
9

Go to settings -> emails and disable "Keep my email address private".

Bakon Jarser
  • 703
  • 6
  • 20
aazimkhani
  • 459
  • 5
  • 8
  • 1
    This is what fixed the error for me. BTW, This is done on https://github.com/settings/emails : https://github.com > Click your profile picture > settings > Emails > "Keep my email addresses private " – AllisonC May 09 '20 at 18:47
7

If you still don't want to expose your email address:

  1. Go to https://github.com/settings/emails and save your "noreply address".

  2. Set your git email address to this noreply address, either with the command git config --global user.email "XXXXXXXX+username@users.noreply.github.com" or inside GitHub Desktop's preferences.

  3. Save somewhere the changes that you want to push.

  4. Revert changes in your last commits, as they were signed with the previously configured email address.

  5. Restore the changes that you saved.

  6. Commit.

  7. Push.

jotaelesalinas
  • 1,387
  • 1
  • 11
  • 24
6

I ran into this problem too. It is an easy fix in Github Desktop by going to File -> Options -> Git and clear the Username and Email fields and save it. Then if you are logged in to GitHub it will fill them in with correct information.

Florent Roques
  • 2,424
  • 2
  • 20
  • 23
Eli
  • 61
  • 2
  • 5
1

You're likely pushing a commit that is signed using your email address, and in your settings on Github. You can change this behavior by either going to GitHub (browser) clicking on the user icon on the top right corner -> Settings -> Emails and unchecking the box that says "Block command line pushes that expose my email", make your email not private (right above that option), or sign your commits with a public email.

0

If you are using GitHub Desktop there is the possibility to reverting the commit (go to "History" tab and right click on the commit to revert). Then, change your email to your private email, and commit again. And then you can push.

Ubikitina
  • 11
  • 3
0

@raider33 solution works but if you need to do it for all previous commits, then it is described in GitHub's "Amending older or multiple commit messages" section

CyxouD
  • 131
  • 1
  • 7