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.

Answers


I have the exact same problem. As a temporary solution, I have this in my .bashrc:

alias git='GIT_AUTHOR_EMAIL=$(
      p=$(pwd)
      while [[ $p != "$HOME" ]]; do
        [ -e $p/.gitemail ] && cat $p/.gitemail && break
        p=$(dirname $p)
      done) GIT_COMMITTER_EMAIL=$(
      p=$(pwd)
      while [[ $p != "$HOME" ]]; do
        [ -e $p/.gitemail ] && cat $p/.gitemail && break
        p=$(dirname $p)
      done) /usr/bin/git'
alias g=git

This way I've got two different .gitemail files in the parent directories:

  • ~/work/.gitemail
  • ~/github/.gitemail

Note that I'm only switching user.email this way, everything else is centralized in ~/.gitconfig. It's a solution, but it's not great.

Hoping someone on StackOverflow has a better idea...


Need Your Help

DIV tag inside of P looking weird in the DOM tree

html dom

Looking at any web inspector, the following markup is outputting unexpected (at least to me) results:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.