TIL: multiple git-identities on one machine

Turns out you can have multiple Git identities alongside each other on one Machine without needing to set them locally for each repository!

It still involves multiple .gitconfig files, but it’s a lot less work than configuring an endless amount of repos!

First, set the global config like this:

# File: ~/.gitconfig
[user]
  name = Kevin Gimbel
  email = kevin@gimbel.dev

[includeIf "gitdir:~/AOE/"]
    path = ~/AOE/.gitconfig

Now in ~/AOE/.gitconfig I configure the following

# File: ~/AOE/.gitconfig
[user]
  name = Kevin Gimbel
  email = kevin.gimbel@aoe.com

In ~/AOE/ I have all repositories related to my work, and whenever I work in a sub-directory the identity with the e-Mail address of my work is being used!

Source: https://stackoverflow.com/a/3860139