gitemailgit-config

Different .gitconfig for a given subdirectory?


I use two different git emails, one for work and one for public projects. Initially I thought that I could create a separate .gitconfig with a different email in a folder where all my public repos are in, and that git would respect that, but alas it seems that doesn't work. What's the best way to easily setup something similar? I want to avoid having to specifically change the email in each public repo.


Solution

  • The real answer is that its impossible.

    However, thanks to @pithyless , and because I was already using a custom 'c' function to switch directories followed by an auto ls, this is what I'm doing now:

    # cd + ls, and change git email when in personal projects folder 
    function c {
      if [[ "`abspath $1`" == *"$HOME/Projects"* ]]; then
        export GIT_AUTHOR_EMAIL="personal@gmail.com"
      else
        export GIT_AUTHOR_EMAIL="me@work.com"
      fi
      cd "${@:-$HOME}" && ls;
    }