Quick Fix: If you’re seeing “push declined due to email privacy restrictions” on GitHub, this is likely because your Git email doesn’t match your GitHub noreply email. Here’s how to fix it in 2 minutes.
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 authentication issues, so we’ll cover those too.
What’s Causing This Error?
Here’s what’s happening behind the scenes:
- You’ve enabled GitHub’s email privacy feature (which is good for security!)
- Your Git configuration is still using your public email instead of your GitHub noreply email
- 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:
- Head over to GitHub Email Settings
- Look for your noreply email (it’ll look like
ID+username@users.noreply.github.com) - 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}"
echo "Configuration updated. If you have existing commits to fix, run:"
echo "git rebase -i HEAD~n # where n is the number of commits to fix"
echo "Then change 'pick' to 'edit' for each commit and run:"
echo "git commit --amend --reset-author"
echo "git rebase --continue"Step 3: Fix Any Existing Commits
If you’ve already made commits with the wrong email, here’s how to fix them:
Start an interactive rebase:
git rebase -i HEAD~n # where n is the number of commits to fixFor each commit, change
picktoeditFor 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:
Check your current Git email:
git config --global user.emailCompare it against the noreply address on your GitHub Email Settings page. The two must match exactly, including the numeric ID prefix.
Common Problems and Their Solutions
Wrong Email Format
- Make sure you’re using the full noreply email
- It should look like:
ID+username@users.noreply.github.com
Multiple Git Configurations
Check your local repository config:
git config --local user.emailCheck your global config:
git config --global user.email
SSH Key Issues
Test your SSH connection:
ssh -T git@github.comCheck 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
Email Configuration
- Always use your GitHub noreply email for Git commits
- Keep email privacy enabled in GitHub settings
- Regularly check your Git configuration
Authentication
- Use SSH keys for authentication (it’s more secure!)
- Rotate your SSH keys periodically
- Always use a strong passphrase
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:
- Fix Permission Denied (publickey) - Fix SSH key and GitHub authentication errors
- Learn Git - Get started with Git and GitHub
- Multiple GitHub Accounts - Manage multiple accounts like a pro
- Configure Your Shell - Set up your development environment
- Death by 1000 Cuts - Understanding technical debt
Comments #