Git error "Your push would publish a private email address"

In this blog post I look at how to resolve the Git error "your push would publish a private email address" .

Your push would publish a private email address
Your push would publish a private email address

So I hit an error trying to do my first pull request (PR) into the Octopus Deploy Documentation.   I had forked the repository and was working on it locally on my own machine within VS Code.

The push to my fork kept failing and I initially thought, oh it's probably my setup, I probably haven't linked VS Code/GitHub together, but when I read the error I was a bit baffled.

It was telling me:

Error "Your push would publish a private email address"

I did remember making sure my email addresses on GitHub were private when I left Microsoft.

On investigating the issue I realised there were two solutions.  Make my email addresses public again or use the randomly generated email that GitHub give you for these situations.

Find your GitHub email address

Your GitHub no reply address is in your GitHub Personal Settings → Emails.  It is mentioned just below the Keep my email address private checkbox.

GitHub no reply email address
GitHub no reply email address

Configure Git to use your GitHub email address

You want to open VS Code or a Windows Terminal or your chosen IDE for using with GitHub and configure this new email address to be used for your commits.

The following command will set the email address to be used for every repository that you have on your computer:

git config --global user.email "{ID}+{username}@users.noreply.github.com"

However, if you only want to use the email address for a single repository then this is the command you should use:

git config user.email "{ID}+{username}@users.noreply.github.com"

Reset the author information on that last commit

You now need to reset the author information on that commit that just failed for you.  

git commit --amend --reset-author

Push that commit

You can now push that commit and it will be successful and future commits will use the no reply email address as well.