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:
- You have enabled GitHub’s email privacy feature
- 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:
- Find your noreply email in GitHub Email Settings
- 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:
Verify your Git email configuration:
git config --global user.email
Check if your noreply email is correct in GitHub settings
Try pushing with verbose output:
git push -v
Best Practices
- Always use your GitHub noreply email for Git commits
- Enable email privacy in GitHub settings
- Keep your Git configuration up to date
- Use SSH keys for authentication