Last Updated: March 02, 2016
·
423
· jmervine

ZSH: auto set git user.email for work repos

WORK_REPO=corp
WORK_EMAIL=user@corp.com
function _git_work_email {
  if test -d .git; then
    if test "$(git remote -v | grep $WORK_REPO)"; then
      git config --local user.email $WORK_EMAIL
    fi
  fi
}
chpwd_functions=(${chpwd_functions[@]} "_git_work_email")

1 Response
Add your response

git config --local user.email have to be done just once per clone, as the setting is stored in .git/config. But instead you are doing it every time you enter the repo.

It would be better to do that in a git post-checkout hook.

over 1 year ago ·