mkrieger1
mkrieger1

Reputation: 23139

Why does Git know my name when it is not configured?

I discovered that I haven't configured the user.name variable in Git: git config user.name prints nothing (also with --system or --global or --local).

My full name is also not contained in the output of env, only my login name, which is different.

Nonetheless, all my commits are attributed to my real first and last name.

How does Git know it?


Clarifications:

Upvotes: 3

Views: 807

Answers (2)

mkrieger1
mkrieger1

Reputation: 23139

Unless specified in the Git configuration or in environment variables, Git will try to look up the username in the password file. The lookup is performed in the fmt_ident function.

Upvotes: 2

user7018603
user7018603

Reputation:

It might be the case that you have environment variables set:

The final creation of a Git commit object is usually done by git-commit-tree, which uses these environment variables as its primary source of information, falling back to configuration values only if these aren’t present.

GIT_AUTHOR_NAME is the human-readable name in the “author” field.

GIT_AUTHOR_EMAIL is the email for the “author” field.

GIT_AUTHOR_DATE is the timestamp used for the “author” field.

GIT_COMMITTER_NAME sets the human name for the “committer” field.

GIT_COMMITTER_EMAIL is the email address for the “committer” field.

GIT_COMMITTER_DATE is used for the timestamp in the “committer” field.

EMAIL is the fallback email address in case the user.email configuration value isn’t set. If this isn’t set, Git falls back to the system user and host names.

Source: https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

Upvotes: 3

Related Questions