Ever tried pushing to GitHub and seen that frustrating “push declined due to email privacy restrictions” error? I’ve been there, and I know how annoying it can be. Let me walk you through exactly how to fix this issue and prevent it from happening again. This error often goes hand-in-hand with SSH key configuration and Git authentication issues, so we’ll cover those too.

What’s Causing This Error?

Here’s what’s happening behind the scenes:

  1. You’ve enabled GitHub’s email privacy feature (which is good for security!)
  2. Your Git configuration is still using your public email instead of your GitHub noreply email
  3. Your commits were made with an email that doesn’t match your GitHub account

Common Error Messages You Might See

You’ll probably see one of these variations in your terminal:

! [remote rejected] main -> main (push declined due to email privacy restrictions)
! [remote rejected] master -> master (push declined due to email privacy restrictions)
! [remote rejected] (push declined due to email privacy restrictions)

Let’s Fix This Step by Step

Step 1: Find Your GitHub Noreply Email

First things first, let’s get your GitHub noreply email:

  1. Head over to GitHub Email Settings
  2. Look for your noreply email (it’ll look like ID+username@users.noreply.github.com)
  3. Copy this email address - we’ll need it in a moment

Step 2: Update Your Git Configuration

I’ve created a simple script to help you update your Git configuration. Here’s how to use it:

#!/bin/sh
# Fix GitHub push declined due to email privacy restrictions
# See more details at https://jeffbailey.us/blog/2020/01/20/push-declined-due-to-email-privacy-restrictions-on-github/

echo "Enter your GitHub noreply email (e.g., 999999+username@users.noreply.github.com)"
read -r github_email

# Update Git configuration
git config --global user.email "${github_email}"

# Fix existing commits
git rebase -i
git commit --amend --reset-author
git rebase --continue

# Push your changes
git push

Step 3: Fix Any Existing Commits

If you’ve already made commits with the wrong email, here’s how to fix them:

  1. Start an interactive rebase:

    git rebase -i HEAD~n  # where n is the number of commits to fix
    
  2. For each commit, change pick to edit

  3. For each commit, run:

    git commit --amend --reset-author
    git rebase --continue
    

Troubleshooting Common Issues

Let’s Check Your Git Configuration

First, let’s verify your current setup:

  1. Check your current Git email:

    git config --global user.email
    
  2. Check your GitHub noreply email:

    git config --global user.name
    

Common Problems and Their Solutions

  1. Wrong Email Format

    • Make sure you’re using the full noreply email
    • It should look like: ID+username@users.noreply.github.com
  2. Multiple Git Configurations

    • Check your local repository config:
      git config --local user.email
      
    • Check your global config:
      git config --global user.email
      
  3. SSH Key Issues

    • Test your SSH connection:
      ssh -T git@github.com
      
    • Check your SSH key permissions:
      ls -l ~/.ssh/
      
    • Need more help? Check out our guide on setting SSH key permissions

Best Practices to Keep in Mind

  1. Email Configuration

    • Always use your GitHub noreply email for Git commits
    • Keep email privacy enabled in GitHub settings
    • Regularly check your Git configuration
  2. Authentication

    • Use SSH keys for authentication (it’s more secure!)
    • Rotate your SSH keys periodically
    • Always use a strong passphrase
  3. Repository Management

    • Keep your repository clean and organized
    • Write clear, descriptive commit messages
    • Follow Git workflow best practices

Want to Learn More?

Here are some related guides that might help:

Helpful References