**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 key configuration]({{< ref "setting-ssh-key-permissions" >}}) and [Git authentication]({{< ref "github-com-permission-denied-publickey" >}}) 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:

```sh
! [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:

```sh
#!/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:

1. Start an interactive rebase:

   ```sh
   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:

   ```sh
   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:

   ```sh
   git config --global user.email
   ```

2. Check your GitHub noreply email:

   ```sh
   git config --global user.email
   ```

### 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:

     ```sh
     git config --local user.email
     ```sh
   - Check your global config:

     ```sh
     git config --global user.email
     ```

3. **SSH Key Issues**
   - Test your SSH connection:

     ```sh
     ssh -T git@github.com
     ```sh
   - Check your SSH key permissions:

     ```sh
     ls -l ~/.ssh/
     ```sh
   - Need more help? Check out our guide on [setting SSH key permissions]({{< ref "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:

- [Setting SSH Key Permissions]({{< ref "setting-ssh-key-permissions" >}}) - Master SSH key setup
- [GitHub Permission Denied]({{< ref "github-com-permission-denied-publickey" >}}) - Fix SSH authentication issues
- [Learn Git]({{< ref "learn-github" >}}) - Get started with Git and GitHub
- [Multiple GitHub Accounts]({{< ref "how-do-i-use-multiple-github-accounts" >}}) - Manage multiple accounts like a pro
- [Configure Your Shell]({{< ref "how-do-i-configure-my-shell" >}}) - Set up your development environment
- [Death by 1000 Cuts]({{< ref "/blog/1000-deadly-cuts-x/death-by-1000-cuts/index.md" >}}) - Understanding technical debt

## Helpful References

- [GitHub Email Privacy Documentation]
- [GitHub Email Settings]
- [Git Configuration Guide]
- [GitHub SSH Key Setup]

[GitHub's email privacy feature]: https://github.com/blog/2346-private-emails-now-more-private
[GitHub Email Settings]: https://github.com/settings/emails
[GitHub Email Privacy Documentation]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-user-account/managing-email-preferences/setting-your-commit-email-address
[Git Configuration Guide]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
[GitHub SSH Key Setup]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent