Conditional Git Identities

Scenario: You have two different Git identities (i.e. ssh key, name, email, etc) on the same machine, e.g. one for work and one for personal projects. The projects live in separate folders.

Possible solution: Use conditional includes in your Git config.

What does this look like? The file structure looks like:

$ tree
├── .gitconfig
└── projects
    ├── personal
    └── work
        └── .gitconfig

The two .gitconfig files look like:

$ cat /home/user/.gitconfig
   name = Hacker Name
   email =
   editor = vim
[includeIf "gitdir:~/projects/work/"]
   path = ~/projects/work/.gitconfig
$ cat /home/user/projects/work/.gitconfig
   sshCommand = ssh -i ~/.ssh/other_key -F /dev/null
   email =
   name = Work Name