gitgit-config

Which git environment variables (AUTHOR, COMMITTER) must be set so it represents the same config as `user.name` and `user.email`?


I usually set a developer's config on their developer machine via:

git config --global  user.name 'developer name'
git config --global  user.email 'developer email'

This would write the config in

~/.gitconfig

For specific Ubuntu developer server, the ~/.gitconfig file is not available during the relevant config (as the home directory is mounted at a later step -- I don't want to change that yet.)

So I want to add some basic config via environment variables. (I do not want to use --system config level as the file /etc/gitconfig may be overwritten by other scripts.)

I know that there is a difference between author and committer. I am not so clear what user.name and user.email refers to.

Does it set both? Only one?

For now I have in my /etc/profile.d/git-config.sh:

export GIT_AUTHOR_NAME='developer name'
export GIT_AUTHOR_EMAIL='developer email'

Yet should or should I not set the GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL as well?

Which git environment variables must be set so it represents the same config as user.name and user.email?

I wonder if there might be some weird behavior on the machine in scope of rebases, cherry-picks, squashing or merges that I didn't think about.


Solution

  • https://git-scm.com/docs/git-config#Documentation/git-config.txt-username

    The user.name and user.email variables determine what ends up in the author and committer fields of commit objects.

    Both author and committer.

    If you need the author or committer to be different, the author.name, author.email, committer.name, or committer.email variables can be set.

    All of these can be overridden by the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, and EMAIL environment variables.

    Which git environment variables must be set so it represents the same config as user.name and user.email?

    All 4.