0

If I run git config --get user.email, it displays my current email address. Is it possible to configure git such that I can set a value of the email for a commit, but it won't display it with the --get switch?

Alternatively, can I just set an environment variable such that git config --get user.email won't get anything, but my commits will still have my email? Or can my commits use a unique identifier other than my email address?

I had a brief look at the git-config documentation page, looking for mentions of --get and "email". The environment variables look promising but I haven't tried them.

Related question: Why does git ask for users' email address?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
  • 1
    What an odd requirement..... I know this looks like a rabbit hole but.... *why*? – Romain Valeri Aug 10 '23 at 10:29
  • @RomainValeri Moq recently attempted to get users’ (hashed) email address using that command: https://www.cazzulino.com/sponsorlink.html – Andrew Grimm Aug 10 '23 at 10:32
  • 3
    If you want `git config --get user.email` to print nothing, I think you need to leave `user.email` unset. When you make a commit, specify `GIT_AUTHOR_EMAIL` and `GIT_COMMITTER_EMAIL` or use `-c user.email=xxx`. The value of these variables can be any string. It does not have to be an email address. – ElpieKay Aug 10 '23 at 10:36

1 Answers1

1

You cannot make git config unable to fetch the email that's used, because git config uses the same machinery as Git uses. However, you can avoid setting (or unset) user.email and use the environment variable EMAIL, which will set the value if user.email and the Git-specific environment variables are not set. I do this and it works great.

The full details are in the git-commit manual page.

bk2204
  • 64,793
  • 6
  • 84
  • 100