293

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user156060
  • 3,083
  • 3
  • 10
  • 7
  • 3
    Does this answer your question? [Meaning of the GitHub message: push declined due to email privacy restrictions](https://stackoverflow.com/questions/43378060/meaning-of-the-github-message-push-declined-due-to-email-privacy-restrictions) – Yuvraj Patil Jul 22 '21 at 14:25

7 Answers7

677

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.

Winfried
  • 9,243
  • 4
  • 26
  • 24
  • 52
    This should be the accepted answer. @sofia-fernandez answer can expose email addresses. Is there any way you can make this a little shorter and more readable? You have two major sections where the only difference is the `--global` flag – Connor Jul 05 '18 at 18:04
  • 1
    I had some trouble with the Linux interface (used the SourceTree terminal and it has been some time since I used VI), you can add `-m ` if you want to avoid that. – MikeL Aug 14 '18 at 14:05
  • Is this like with Craigslist, where I still get the email sent to my anonymized address, but now instead of getting email directly from the sender, now I get it delivered to me from GitHub, via their email anonymous re-sender? – Elliptical view Dec 30 '20 at 00:05
  • 6
    This should be the answer. specifically if you haven't done 'git commit --amend --reset-author' and just modified the email by editing the .git/config etc. you may still get this error. Don't forget to `git commit --amend --reset-author` – A. K. Jan 26 '21 at 23:31
  • Get your no-reply mail: Go to https://github.com/settings/emails, check the "Primary email address" section, and you'll see a email address. It is `some_number+username@users.noreply.github.com`. This can be used in the command `git config --global user.email "your_email_address"`. – chenghuayang Jul 28 '21 at 14:44
  • For the first time to push files, remember to `git commit -m "first commit"` again after you enter the new no-reply email address. (I was following the tutorial on a new Github repository, and failed even though I followed the answer. That's due to I commited first then enter the email.) – chenghuayang Jul 28 '21 at 14:45
  • Correct me if I'm wrong, but I don't think GitHub uses the ID before your username anymore. Instead of "{ID+username}@users.noreply.github.com" I think it's just "{username}@users.noreply.github.com." – Michael Cox Feb 13 '22 at 22:46
  • 4
    I think `git commit --amend --reset-author --no-edit` is little faster as it won't ask you to edit the commit message. – Carl G May 08 '22 at 04:12
  • Just an alternative to reset-author: ``git commit --amend --author="John Doe "`` – Dr.G Apr 08 '23 at 00:07
116

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.
Jade
  • 3,156
  • 1
  • 34
  • 44
sofia-fernandez
  • 1,384
  • 1
  • 9
  • 3
  • 45
    This is a solution but might actually expose your email address. If you have any commits that haven't been pushed yet, you'll need to uncheck **Block command line pushes that expose my email.** Then you can push those pending commits. Afterwards, update your email address to the no-reply email address and check **Block command line pushes that expose my email** again to keep your address private. – SvenAelterman Jul 20 '17 at 18:54
  • 7
    @SvenAelterman `update your email address to the no-reply email address` where? In the github settings or on your local machine somewhere that's presumably sending/using your private email address? It strikes me as counterintuitive that I might be supposed to copy and past an email address generated by github directly back into github rather just click on a checkbox, therefore I assume that reading is incorrect. Or is it?? – hippietrail Oct 11 '17 at 06:48
  • @hippietrail git help tells you to copy the no reply email to your git config --global setting on the client. it will be blocked as private first use too, but unblock for the first push, then block subsequent pushes. you only need to unblock if you change the email address and need to push it to the public repo – CharlieS Mar 03 '18 at 06:53
  • 21
    To change the email for your latest commit use `git commit --amend --author="Author Name "` – Daniel Apr 28 '18 at 07:29
  • 25
    Much better to use @Winfried 's solution [here](https://stackoverflow.com/a/51097104/7872793). Won't expose your email address publicly – Connor Jul 05 '18 at 18:20
  • 15
    Agreed, the correct answer is @Winfried's https://stackoverflow.com/a/51097104/7872793. – Shanerk Oct 08 '18 at 20:52
  • Re *"expose your email address*": In what way and how? Who will be able to see it? E.g., can it be seen by scrapers of GitHub pages? Or does it require using Git or being logged in at GitHub? – Peter Mortensen Jun 29 '20 at 15:39
  • For our purpose, at my company, @sofia-fernandez's solution is the preferred solution. The reason being that we check "Keep my email address private" not to keep our email private, but to prevent web-based operations from being stamped with an incorrect email. We use our private GitHub account for company usage also, as encouraged by GitHub. But when you do web-based operations it will always use the primary email. So in order to not stamp a company commit with the private email, or vice versa, we check that option. And then we uncheck "Block command line pushes that expose my email". – Jonas Bang Christensen Nov 02 '20 at 13:16
  • Guys, even after you change all these kooky email settings above it still fails to push your files to GitHub. Your Git "push" has to be reset on your local side, as it has cached the old settings in Visual Studio (or wherever your repo is). So go right click your project or master and choose "reset". Make sure you have committed your local changes first and you dont lose anything. Then try pushing to GitHib again. Peace – Stokely Jul 02 '22 at 02:05
34
  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
Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
6

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.

Ramesan PP
  • 134
  • 1
  • 5
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • Thanks! I anonymized my email adres and that solved the issue! – user156060 May 09 '17 at 08:06
  • Using the anonymized email address is a good solution. If you created it prior to July 18, 2017, you may want to do it again to get 7 random digits added to it. – SvenAelterman Jul 20 '17 at 18:50
  • [Winfried's answer](https://stackoverflow.com/questions/43863522/your-push-would-publish-a-private-email-address-error/51097104#51097104) is the self-contained answer. – Peter Mortensen Jun 29 '20 at 15:43
-3

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

GitHub Settings

Vikrant
  • 4,920
  • 17
  • 48
  • 72
Peter Doherty
  • 121
  • 1
  • 10
-3

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.

Bhushan Uniyal
  • 5,575
  • 2
  • 22
  • 45