Git requires that you provide a name and an email address in order to commit. These values are inserted in every commit that you make and they must be nonempty and meet some basic validation. Conventionally, the name is your personal name, but that isn't required by Git itself, although projects you contribute to may require it.
However, having said that, you don't have to provide them in
~/.gitconfig, or even in any config file at all. Git will first of all read from the environment variables
GIT_COMMITTER_EMAIL if they exist. However, usually this is not a good idea because it overrides values when you use
git commit --amend, and you want to use another technique.
git-commit(1) explains the other options:
In case (some of) these environment variables are not set, the information is taken from the configuration items
user.email, or, if not present, the environment variable
EMAIL, or, if that is not set, system user name and the hostname used for outgoing mail (taken from
/etc/mailname and falling back to the fully qualified hostname when that file does not exist).
committer.name and their corresponding email options override user.name and user.email if set and are overridden themselves by the environment variables.
The typical usage is to set just the
user.email variables; the other options are provided for more complex use cases.
I typically leave my name in
user.name and set
EMAIL appropriately in my shell config. Do note that some programs, most notably Homebrew, are broken and filter
EMAIL from the environment, so this won't work in all circumstances. It isn't a good idea to rely on the system GECOS field and mail setup being correct, because usually it isn't.
Finally, note that you can use a different config file, usually in
~/.config/git/config to store values that you don't want to store in the main
~/.gitconfig or check in to your dotfiles repository. I do this for values like
commit.gpgsign, since not all systems I use have my private keys and can sign commits, and therefore it's system dependent whether I can sign and what keys I use.