Can git configuration be set across multiple repositories?

I have found no way to configure git at this fourth level. The only way seems to be per-command configuration value overrides using git -c key=value.

My current hacky solution is to define a shell function that serves as a wrapper for git. When called, it passes the arguments onto the system git command, but not before checking on the present working directory and adding an extra argument to the command if applicable.

function git () {
    case "$PWD" in
        /path/to/repos/*)
            command git -c [email protected] "$@"
            ;;
        *)
            command git "$@"
            ;;
    esac
}

You can configure the email address for git with the environment variable GIT_AUTHOR_EMAIL. If you combine this with Execute bash scripts on entering a directory or directory specific shell configuration with zsh you can easily change the settings per directory or parent directory, e.g. if you enter into a directory in ~/work you can automatically adjust the environment variables to change your email address.


See the solution based on git configuration:

http://gik.firetrot.com/index.php/2018/05/06/git-configuration-across-multiple-repositories/

Add to “~/.gitconfig” file:

    [includeIf "gitdir:~/work/project1/.git"]  
      path = .gitconfig-project1  

Create “~/.gitconfig-project1″ file with content:

    [core]  
      sshCommand = "ssh -i ~/.ssh/project1 -F /dev/null"  

    [user]  
      name = user1  
      email = [email protected]  

Tags:

Shell

Git