#401·go-git

Environment variables are not loaded for commit action

Author: endoramaCreated Oct 27, 2021Updated Sep 28, 2026
Labelsenhancementstale

I'm using go-git through a project and faced this error: [...]: author field is required.

In my Git configuration I do not specify the user.email field; here is the excerpt:

   1   │ [user]
   2   │     name = Edoardo ...
   3   │     useConfigOnly = true

This configuration forces to set user.email setting for each repo.

I went on debugging this:

This behaviour seems to contradicts the git documentation about Environment variables. Under Committing in Git Internals Environment variables is written:

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.

(Incidentally these variables include GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL, which should override any file based configuration and I tried using to overcome the mentioned error).

Expected behaviour: go-git follows git behaviour and respects environment variables at commit time, not relying only on file based configurations

By looking at other issues I noticed aligning with what git does is important, so I would contribute a PR to change this behaviour by loading specified environment variables in loadConfigAuthorAndCommitter before system configuration and configuring author and committer accordingly to what git docs say.