Fix GitHub Push Declined Due to Email Privacy Restrictions

If you’re seeing the error “push declined due to email privacy restrictions” when pushing code to GitHub, this guide will help you fix it quickly.

What Causes This Error?

This error occurs when:

  1. You have enabled GitHub’s email privacy feature
  2. Your Git configuration is using your public email instead of your GitHub noreply email

How to Fix It

Follow these steps to resolve the issue:

  1. Find your noreply email in GitHub Email Settings
  2. Run this script to update your Git configuration:
#!/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

Troubleshooting

If you’re still having issues:

  1. Verify your Git email configuration:

    git config --global user.email
    
  2. Check if your noreply email is correct in GitHub settings

  3. Try pushing with verbose output:

    git push -v
    

Best Practices

  1. Always use your GitHub noreply email for Git commits
  2. Enable email privacy in GitHub settings
  3. Keep your Git configuration up to date
  4. Use SSH keys for authentication