Different .gitconfig based on current path

Git v1.6.0 release note contains a clue :

GIT_CONFIG, which was only documented as affecting "git config", but
actually affected all git commands, now only affects "git config".

And git v1.8.2 fixes that new behavior for git clone command which was still affected.

The workarounds I can see of interest are:

  • Use git with as many users as needed (su command-line tool can help).
  • Writing aliases like alias gitcommit='git commit --author=$(git config user.email)' (ugly).
  • Copy your configuration file into your repo local configs (any config modification must then be propagated by-hand).
  • Fake ~/.gitconfig lookup through HOME environment variable override. Ex: HOME=~/.gitconfig/user-a/ git commit should read ~/.gitconfig/user-a/.gitconfig (may have some other side effects).

Also, if you go with chpwd zsh hook, be careful to support multiple zsh running in multiple repositories.

Tags:

Git

Zsh