push declined due to email privacy restrictions

Although I’ve set my git --global user.email to the no-reply email adress which I fund in my github email preferences, I still get this error:

$ git push origin readme-dev

Counting objects: 8, done.         
Delta compression using up to 4 threads.                               
Compressing objects: 100% (8/8), done.                                 
Writing objects: 100% (8/8), 984 bytes | 984.00 KiB/s, done.           
Total 8 (delta 6), reused 0 (delta 0)                                  
remote: Resolving deltas: 100% (6/6), completed with 5 local objects.
remote: error: GH007: Your push would publish a private email address.
[...]
! [remote rejected] readme-dev -> readme-dev (push declined due to email privacy restrictions)
9 Likes

Hi @troyciv,

If you run git config --local --list does it display a different email than you have in your global Git config?

Thanks!

4 Likes

It didn’t show any email. I also tried to add a local email which than showed up in the git config --local --list. Still got the same error.

However, when I try to push my local master branch to the remote master branch it seems to work, only my newly created local development branch will not push with git push origin dev

1 Like

Can you show the output of the command git config --show-origin --get-regexp "user.*"?

1 Like
file:/home/user/.gitconfig user.name Troyciv
file:/home/user/.gitconfig user.email 14926781+Troyciv@users.noreply.github.com
file:.git/config user.email 14926781+Troyciv@users.noreply.github.com

@troyciv it looks like everything is configured correctly now but it is possible that you have some commits on that other branch that were written with some other values. You should be able to use the command git log --first-parent --no-merges when on the other branch to take a look at the commit information to find which commits have non-private email information. Then you can use git rebase -i to rewrite those commits so they have the new private email information.

4 Likes

I just encounterd the same problem.

The steps I took to fix (thanks for the advice on this thread) were roughly as follows:
git config --global user.email “YOUR_EMAIL_ADDRESS_HERE@users.noreply.github.com
git rebase -i
git commit --amend --reset-author
git rebase --continue
git push

I found rebase -i allowed me to edit the commit message but retained the previous (private) email address in the log.
The commit --amend --reset-author seemed to be the easiest way to replace the offending email address.

248 Likes

That solved it, thank you

1 Like

I’m not at all sure what happened, but this ended up costing me a day’s work. I followed the directions exactly, and ended up losing a commit that hadn’t yet been pushed.

5 Likes

Go to Settings/Emails on your GitHub account and uncheck “Block command line pushes that expose my email”

8 Likes

Just need to remove one checkbox as described here:

https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions

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 settingsand then pushing again.

87 Likes

This is the perfect solution.

This was EXACTLY what I needed. I couldn’t figure out why nothing was being pushed. As soon as I unchecked that box, everything wents smoothly. Thank you!

I had the same problem, and spent a long time fiddling until I realized that git wasn’t taking the userid and email from *either* config file, but from the environment variables $GIT_AUTHOR_EMAIL and $GIT_AUTHOR_NAME (which I had long-since forgotten setting).

There seem to be at least four places to check (I *think* this may be the order git checks them in):

  • git commit --author “John Doe <jane@doe.com>”
  • environment variables $GIT_AUTHOR_EMAIL, $GIT_AUTHOR_NAME, etc.
  • .git/config in the current repo
  • ~/.gitconfig

For all I know, there may be more…

2 Likes

In my case what happened was that I changed my email policy to be private and then git generates a new one to be used by me. I should setup this new email in my local machine:

git config --global user.email "rjesususa@users.noreply.github.com"
3 Likes

This is actually the answer. I don’t know why the other was marked as the answer?

Thanks It Worked for me

@nicks9188 wrote:

Just need to remove one checkbox as described here:

 

https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions

 

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 settingsand then pushing again.

1 Like

Works for me, thnx

@nicks9188 wrote:

Just need to remove one checkbox as described here:

 

https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions

 

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 settingsand then pushing again.

remote: error: GH007: Your push would publish a private email address.
.
.
.
To https://github.com/AdiedX/message-template-service.git
! [remote rejected] CC-398-new-download-email-template -> CC-398-new-download-email-template (push declined due to email privacy restrictions)
error: failed to push some refs to 'https://github.com/AdiedX/message-template-service.git'
➜ message-template-service git:(CC-398-new-download-email-template) ✗ git push --force

Root cause for me

I had recently changed my Emails settings to make my email private. Github wouldn’t allow publishing of the private email. I made my email public again. Now it works.

1 Like

Had the same problem  and solved it by going into my email preference and unchecking the options

1.block command line pull that expose my email

  1. keep my email praivate
2 Likes