A pull request merged on github.com can put your private email in the repo's history
For anyone who merges pull requests in GitHub's web UI on a repo they plan to make public: unless email privacy is on, the merge commit carries your personal email as its author, and the default merge title adds your handle. Turn on email privacy, set merge titles to the PR title, and have your leak check read every commit's author and committer email.
- Issue
- #10
- Published
- Reading time
- 3 min
- Stack
- GitHub, Git
The story
I was getting a small PowerShell and Markdown repo ready to go public. Before releasing it, I had a leak check that scanned the files and the git history for private terms, and it passed. When I looked at the commits themselves, I found a problem the check couldn't see: the merge commit for a pull request I had merged on github.com listed my personal Gmail address as its author. Its message also held my GitHub handle, because GitHub's default merge title reads Merge pull request #2 from <handle>/<branch>.
My local commits were fine. The commit GitHub made for me was not. Earlier the same day, a push from another repo had been refused with:
remote: error: GH007: Your push would publish a private email address.
That refusal only guards pushes. A merge done in the web UI goes straight into history.
Why I'm sharing this
This catches anyone who merges in GitHub's web UI on a repo that is private now and will be public later. GitHub signs web merges with your account's primary email unless you have turned on email privacy. Once the repo is public, that address is in its history. Rewriting the commit fixes the branch, but GitHub keeps cached views of the old commit until Support removes them, so the repo has to stay private until they do.
The fix
- In GitHub, go to Settings, then Emails, and tick Keep my email addresses private. Web merges then use your
<id>+<user>@users.noreply.github.comaddress. - In the repo's settings, set the default merge commit title to the pull request title, so the handle stops appearing. Through the API, the setting reads back as
PR_TITLE. - Use the noreply address locally as well:
git config --global user.email <id>+<user>@users.noreply.github.com
- Have the leak check read each commit's raw author and committer email (
%aeand%ce, which skip.mailmap) across every ref, and fail on any address that isn't a GitHub noreply address:
git log --all --format='%H %ae %ce'
- For a commit that has already been pushed: rewrite its author and message, force-push, and then check every remote ref. After that, open a GitHub Support ticket asking them to remove cached views of the old commit hash.
To check it worked, merge a test pull request and run the git log line above. The web-made commit should show a noreply author and GitHub's noreply committer.
Use it in your workflow
Check this repo for private email addresses in its git history.
1. Run `git log --all --format='%H %ae %ce'` and list every commit whose author or committer email doesn't end in @users.noreply.github.com.
2. If the repo has a leak-check script, add a check that fails on any such email (use the raw %ae/%ce, not the mailmapped %aE/%cE).
3. Tell me which commits are affected and whether they were made by GitHub's web merge. Remind me to tick "Keep my email addresses private" in GitHub's email settings and to set the repo's merge commit title to the PR title.
Don't rewrite history or push. Show me the plan first.