Is there a workaround for git push using the Github provided noreply email, without unticking "Block command line pushes that expose my email"?

Viewed 1349

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.

1 Answers

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.

Related