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:
- 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}"
# 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:
Start an interactive rebase:
git rebase -i HEAD~n # where n is the number of commits to fix
For each commit, change
pick
toedit
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:
Check your current Git email:
git config --global user.email
Check your GitHub noreply email:
git config --global user.name
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.email
- Check your global config:
git config --global user.email
- Check your local repository config:
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
- Test your SSH connection:
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:
- Setting SSH Key Permissions - Master SSH key setup
- GitHub Permission Denied - Fix SSH authentication issues
- 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