Configuring Git with environment variables
As well as commands like git config --local, Git can also be configured using environment variables.
Whilst working for client projects, I often need to change my email address or clone repositories using a different SSH key.
With environment variables, I can do this:
export GIT_AUTHOR_EMAIL="[email protected]"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/foo -o IdentitiesOnly=yes"
This works well when used with direnv - a tool that manages environment variables based on directory.
This means I can create one .envrc file for the directory containing that client's projects, and it will automatically use the correct SSH key and email address.