git config environment variables

Viewed 777

I hope you can answer me today!

Docs from git help commit says:

COMMIT INFORMATION
  Author and committer information is taken from the following
  environment variables, if set:

      GIT_AUTHOR_NAME
      GIT_AUTHOR_EMAIL
      GIT_AUTHOR_DATE
      GIT_COMMITTER_NAME
      GIT_COMMITTER_EMAIL
      GIT_COMMITTER_DATE

I set GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL variables by doing these commands:

# export GIT_AUTHOR_NAME=".."
# export GIT_AUTHOR_EMAIL=".."
# export GIT_COMMITER_NAME=".."
# export GIT_COMMITER_EMAIL=".."

I checked their content with echo

But git commit command still says me:

# git commit
Author identity unknown

*** Please tell me who you are.

Run

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

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@fedora.(none)')

I need to do it as root for some reason

Yes, I know that I can simply do that git config .. command, but it's curious to me why I can't tell git this info with these environment variables

2 Answers

I need to do it as root for some reason

if you have:

  • set those variables as your regular user, and then executed a sudo git commit
  • or the reverse: set those variables using sudo, and then executed a regular git commit

Then git command would not see the GIT_xxx variables, and fall back to the configuration (which was not set)

It was my typos in settings GIT_COMMITTER_xxx variables (you can see them at question body). Setting actual variables works as intended.

Related