git commits with different EMail addresses

If you do (like me) a lot of git clones for different branches etc on a lot of different projects, the chances are high, that you want to have different EMails for checkins. You can update the local .git/config file for every clone, but that is a error prone process.

I have written an alias for git, which sets the GIT_AUTHOR_EMAIL environment variable according to the setting of the remote origin for the git repo. If it is a local repo, the standard EMail from .gitconfig is used.

It is used in zsh by me, so if you use a different shell, your mileage may vary.

function git_email {
  repodir=`/usr/bin/git config --get remote.origin.url`
  reponame=$(basename -- "$repodir")

  if [ $reponame ]
    while read line
      if [[ $repo == $reponame ]]; then
    done < $HOME/.gitemail

  echo $gitemail

# alias
alias git='GIT_AUTHOR_EMAIL=$(git_email) /usr/bin/git'

Here is a part of the .gitemail file i use.

Thanks for reading. Comment on this post!

Back to index