user156060
user156060

Reputation: 3939

Error "Your push would publish a private email address"

I'm very new to GitHub/VCS.

When I try to share my project on GitHub, I get the following error message.

    Can't finish GitHub sharing process
    Successfully created project 'myproject' on GitHub, but initial push failed:
    remote: error: GH007: Your push would publish a private email address.
    failed to push some refs to 'https://github.com/me/myproject.git'

I've googled the error message and got no hits. I've also searched Stack Exchange, but no cigar. How can I solve this issue?

Upvotes: 377

Views: 142577

Answers (8)

Feng.jl
Feng.jl

Reputation: 1

I had the same problem.

If you have multiple Git, you can also refer to my answer.

If you want to continue to use the mailbox, privacy in Settings -> Emails, Keep the Keep my email addresses private and Block command line pushes that expose my email options,

  1. Open terminal, cd ~/.ssh Look for the config file in this directory.
  2. Add User User for each Git in the config file.
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
User {ID}+{username}@users.noreply.gitee.com

Host github.com
Hostname ssh.github.com
Port 443
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
User {ID}+{username}@users.noreply.github.com

Upvotes: 0

Winfried
Winfried

Reputation: 11553

When enabling the “Block command line pushes that expose my email” feature, you’ll also want to configure Git to use your no-reply email address. Don’t worry—this won’t affect your contribution graph. All commits will still be associated with your account.

  1. Open Terminal.

  2. Change the current working directory to the local repository where you want to configure the email address that you associate with your Git commits.

  3. Find your GitHub noreply address in your GitHub's Personal Settings → Emails. It's mentioned in the description of the Keep my email address private checkbox. Usually, it starts with a unique identifier, plus your username.

  4. Set an email address in Git. Use your GitHub-provided no-reply email address.

    • Setting your email address for every repository on your computer

        git config --global user.email "{ID}+{username}@users.noreply.github.com"
      
    • Setting your email address for a single repository

        git config user.email "{ID}+{username}@users.noreply.github.com"
      
  5. Reset the author information on your last commit:

    git commit --amend --reset-author --no-edit
    

If you have multiple commits with your private e-mail address, see this answer.

  1. Now you can push the commit with the noreply e-mail address, and future commits will have the noreply e-mail address as well.

    git push
    

Once you configure Git, commits will use your alternate “noreply” email address, and any pushes that don’t will be rejected.

Upvotes: 905

sofia-fernandez
sofia-fernandez

Reputation: 1438

Warning: This will expose your email address! Each commit includes the email address of the committer and for public repositories, this information is publicly available.

--

I experienced the same error: GH007 message as well and used the following to resolve the issue.

  1. Go to Setting your commit email address.
  2. Follow the Setting your email address for every repository on your computer.
  3. Open your GitHub account, and go to SettingsEmails.
  4. Select the Keep my email address private check box.
  5. Unselect the Block command line pushes that expose my email check box.

Upvotes: 119

Garegin
Garegin

Reputation: 1

I had the same problem, and I couldn't reset the author information on my last commit (as advised here). Instead, I removed .git and did git init again, so no commit change was needed anymore.

Upvotes: -4

Ramesan PP
Ramesan PP

Reputation: 164

There is a solution, w/o exposing your email. The error occurred because you have configured your own email address in the git config --(global|system|local) user.email.

If the same email is your Github email and you have selected the option to make your email private, this error gets flagged by git.

Helpfully, Github provides you with a no-reply email address which you can use for command line actions. Just check your Email settings on your Github Profile.

You can simply remove or undo the commit done with the user.name and before committing changes again, set another email for

git config --(global|system|local) user.email "<no-reply-email-here>".

Now when you try to push changes to your remote repo, the error should be gone.

Upvotes: 6

Yuvraj Patil
Yuvraj Patil

Reputation: 8736

  1. Open Emails section of github.com. Visit https://github.com/settings/emails.

  2. Go to Keep my email addresses private section and note down your donotreply email id.

  3. Open git terminal and set your donotreply email id as your email id using following command:

git config --global user.email "<your_donotreply_email_id"
  1. Revert your recent local commits (with your private email) which are getting failed to be pushed into repository.
git reset --soft HEAD~1 
  1. Stage and push those commits
git add .
git commit –m "<commit_message>"
git push

Upvotes: 38

Burhan Khalid
Burhan Khalid

Reputation: 174624

You have probably enabled (or it is enabled now by default) the email privacy feature of GitHub.

It is detailed on this page at GitHub help.

In short, there is a toggle that you can enable (which is enabled on your account) that prevents any push where the user is your actual email address. You can use an anonymized address instead (or choose to disable the feature).

Details for both options are available at the same page.

Upvotes: 2

Peter Doherty
Peter Doherty

Reputation: 119

I had the same issue. My solution is in the picture below:

GitHub Settings

Upvotes: -4

Related Questions