Abort commit in Git if user.name and user.email are not configured

I use Git heavily with different usernames on different machines. Sometimes, when I clone a repository, I forget to configure user.nameboth and user.email, and when I commit the first commit to a local repository without a specified name, I get

Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

Yes, it’s very clear what and why Git says so. (If I notice him). However, is it possible to suppress this behavior and prevent Git from propagating my username and hostname as the commit username? Why do I ask a question that I do not have [user] name =, and [user] email =in my ~/.gitconfigon a plan: I just use different user names and e-mails to different groups of repositories, and I would like to Git interrupted the commit, if he can not get the user name and e-mail address from configuration. The worst part is that I have a custom git-informativePS1 configured to display the current username and email address on the right, because I had a history of rewriting and pushing several times before I even noticed that there were huge Git warnings for the default username.

Is it possible to abort a commit in Git if user.nameit has user.emailnot been specified by me all over the world? (I suppose this can be fixed with hooks, but the hooks are only local, right?)

+4
source share
2 answers

Yes user.useConfigOnly:

git config --global user.useConfigOnly true

From git-config(1):

Git, user.email user.name,             . ,             , true            config , Git             . false.

+6

, git user.email user.name URL: https://github.com/DrVanScott/git-clone-init

0

Source: https://habr.com/ru/post/1668780/


All Articles