×

Search anything:

push declined due to email privacy restrictions [FIXED]

git

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article, we have explored the reason behind the error "push declined due to email privacy restrictions" along with two approaches to fix this issue while pushing your code changes on GitHub.

Table of contents:

  1. Reason behind the Error
  2. Fix 1: git config
  3. Fix 2: GitHub settings

Reason behind the Error

If you try to push your code changes to a repository on GitHub using the following command you may get the error "push declined due to email privacy restrictions":

git push origin master

Error:

! [remote rejected] master -> master (push declined due to email privacy restrictions)
error: failed to push some refs to 'git@github.com:OpenGenus/cosmos.git'

git did not exit cleanly (exit code 1)

Due to this error, it is not possible to push your changes.

The reason behind this is that since 2020, GitHub has introduced a feature to use a private email address in git commits. Previously, personal email IDs were linked to commits and this information was publically available. Due to this, people were able to scrap and get email IDs for millions of GitHub users. In fact, this was not an issue with Github but a feature of git.

The solution was GitHub provides a private email ID and it is attached with all public actions on GitHub such as merging pull requests.

When pushing code changes from a local system, this error comes as the git config settings have the personal email ID and once committed and pushed, the email gets leaked. To prevent this, GitHub throws this error "push declined due to email privacy restrictions".

Fix 1: git config

The best fix is to update your email in git config settings of your local system and then, continue with push.

If your username on GitHub is "opengenus", then your private GitHub email ID will be "opengenus@users.noreply.github.com".

You can update the email in your git config settings using the following command:

git config --global user.email {username}@users.noreply.github.com

As you have tried to push your changes, you have already committed your changes so we need to update the commit. Use the following command:

git commit --amend --reset-author

Once done, push your code changes to GitHub and it will work smoothly:

git push origin master

Following are the 3 commands to solve this error:

git config --global user.email {username}@users.noreply.github.com
git commit --amend --reset-author
git push origin master

Fix 2: GitHub settings

The second alternative fix is to change the settings in your GitHub profile to turn off the option to use private email. The steps to do this is as follows:

  1. Login to your GitHub profile
  2. Go to https://github.com/settings/emails or use UI options -> Top right corner -> Settings option -> Email option
  3. Untick the following two options:
    3.1. Keep my email addresses private (optional)
    3.2. Block command line pushes that expose my email
  4. You will get a notification stating "Commits pushed with a private email will no longer be blocked."
  5. Click on "Save email preferences" button to save your changes.

Following this, push your changes from your local system and it will work without any error.

With this article at OpenGenus, you must have the complete idea of how to solve this error of "push declined due to email privacy restrictions" while pushing your changes.

Geoffrey Ziskovin

Geoffrey Ziskovin

Geoffrey Ziskovin is an American Software Developer and Author with an experience of over 30 years. He started his career with Haskell and has interviewed over 700 candidates for Fortune 500 companies

Read More

Improved & Reviewed by:


OpenGenus Tech Review Team OpenGenus Tech Review Team
push declined due to email privacy restrictions [FIXED]
Share this