Is there a way to globally configure git
to not automatically generate user's email, if none is set and abort the commit instead?
$ git commit -m "test"
[master (root-commit) 71c3e2e] test
Committer: unknown <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
This can cause serious privacy leaks if the committer is not careful enough to check git
warnings.
Git Config ⚙️Recent versions of Git don't allow to commit without having a name and email address configured for the repository. The email address is an integral part of a commit.
So that someone else can know who committed the change. By the way, it is a simple matter to configure git with a default email address for your commits. It is explained in the Git SCM ebook: http://git-scm.com/book/en/v1/Getting-Started-First-Time-Git-Setup.
Git allows you to set a global and per-project username and email address. You can set or change your git identity using the git config command. Changes only affect future commits. The name and email associated with the commits you made prior to the change are not affected.
Set git config --global user.useConfigOnly true
user.useConfigOnly
Instruct Git to avoid trying to guess defaults for user.email and user.name, and instead retrieve the values only from the configuration. For example, if you have multiple email addresses and would like to use a different one for each repository, then with this configuration option set to true in the global config along with a name, Git will prompt you to set up an email before making new commits in a newly cloned repository. Defaults to false.
This can be done with git
pre-commit hook, following the suggestion by @cupcake.
Create file named pre-commit
like so:
#!/bin/sh
git config user.name >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Error: user.name is undefined. Use 'git config user.name \"Your Name\"' to set it."
exit 1
fi
git config user.email >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Error: user.email is undefined. Use 'git config user.email [email protected]' to set it."
exit 1
fi
If necessary, make it executable with chmod +x pre-commit
Throw this file to global git
hook templates:
On *nix systems this is located at
/usr/share/git-core/templates/hooks
On Windows this can be typically found in
%ProgramFiles%\Git\share\git-core\templates\hooks
Re-initialize your existing git
repos with git init
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With