Once in a while I get the message shown below from Git. My questions regarding this are:
- Why does this happen?
- How can I prevent this from happening again?
- How does this affect my commits or any other Git actions I may take?
I realize similar questions have been posted to Stack Overflow, but I don’t believe they address this message in particular.
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 [email protected]
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1
Git
simply detects you don’t have the following section in your config files:
[user]
name = <your name>
email = <your mail>
<project_path>/.git/config
for the project specific config file.~/.gitconfig
the global config file
When you do:
git config --global user.name "Your Name"
git config --global user.email [email protected]
Git writes that information into the configuration file (--global
means in the global config file).
To have a the correct Author section in a commit like the following example commit:
commit 79eeaa9f22321580a0e5bee6e237331691cd3b68
Author: Sandro Munda <[email protected]>
Date: Thu Jun 8 10:40:05 2012 +0200
My first commit
You need to reset the commit information with the command:
git commit --amend --reset-author
2
That’s simply because you didn’t set your global user.name and user.email and so git has to guess them when creating a new repository.
Use this :
git config --global user.email "[email protected]"
git config --global user.name "ha"
So next time those settings will be used.
If you want to prevent git from guessing automatic values you can set
git config --global user.useConfigOnly true
See https://git-scm.com/docs/git-config#Documentation/git-config.txt-useruseConfigOnly
1
You have not set the default user name and email for you “desktop user account”.
Follow the instructions that you posted to do so.
As my ChatGPT advised me,
You can use a specific email for each git repository. If you use more git accounts, this might come in handy.
git config user.email "[email protected]"
Note that it excludes the --global
flag.