5

If I run git config --global user.email I get: 16969914+jamesray1@users.noreply.github.com.

Then if I run git push with "Block command line pushes that expose my email" ticked in my Github email settings, it doesn't work, with error: GH007: Your push would publish a private email address. in the output. I can't add this email address to Github because it already added (I get an error informing me of that if I try). If I untick "Block command line pushes that expose my email", then git push works. I've read these articles:

I sent a message to Github support, but if anyone has any ideas, feel free to answer.

James Ray
  • 424
  • 3
  • 15
  • Maybe you have a different e-mail set in your repository? What does it say when you just `git config user.email`? – Klas Mellbourn Sep 23 '17 at 17:25
  • Hi Klas, no it's the same email, git config user.email confirmed that. But the issue is sorted now as per @max630's answer. – James Ray Sep 24 '17 at 06:44

1 Answers1

5

I suspect that before you have changed the settings you have made commits which mention your real email. You should now modify your local commits so that they use the github's proxy email

Based on this answer, it would be like (I did not test it!):

$ git filter-branch --commit-filter '
      if [ "$GIT_AUTHOR_EMAIL" = "REAL_EMAIL" ];
       then GIT_AUTHOR_EMAIL="PROXY_EMAIL";
      fi;
      if [ "$GIT_COMMITTER_EMAIL" = "REAL_EMAIL" ];
       then GIT_COMMITTER_EMAIL="PROXY_EMAIL";
      fi; 
      git commit-tree "$@" '  -- @{u}..

This assumes that you don't want to change your name, only emails. The selector @{u}.. I believe should select exatcly those commits which you would push.

max630
  • 8,762
  • 3
  • 30
  • 55
  • 2
    Hi @max630, yes, I made my first push with my real email, which caused a similar output, notifying that making pushes with my real email is blocked. Thanks for the command, it worked! Just pointing out for anyone else who may encounter the same problem that you need to change REAL_EMAIL to your private email, and PROXY_EMAIL to your Github provided email. Otherwise, the command needs no further modification. – James Ray Sep 24 '17 at 06:50
  • Unfortunately I'm getting this error again. `git log` has my private email for every commit, even though `git config --global user.email` returns `16969914+jamesray1@users.noreply.github.com`. Running the following returns `Found nothing to rewrite`: `git filter-branch --commit-filter '` `if [ "$GIT_AUTHOR_EMAIL" = "REAL_EMAIL" ];` `then GIT_AUTHOR_EMAIL="PROXY_EMAIL";` `fi;` `if [ "$GIT_COMMITTER_EMAIL" = "REAL_EMAIL" ];` `then GIT_COMMITTER_EMAIL="PROXY_EMAIL";` `fi;` `git commit-tree "$@" ' -- @{u}..` – James Ray Oct 15 '17 at 12:12