Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active October 14, 2022 03:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asaaki/c5e3025bdec8d42c3e51ef4ae93aa03a to your computer and use it in GitHub Desktop.
Save asaaki/c5e3025bdec8d42c3e51ef4ae93aa03a to your computer and use it in GitHub Desktop.
Using different emails and GPG keys for work and personal stuff on GitHub
[core]
# ...
[init]
defaultBranch = main
[commit]
gpgsign = true
# you want that to have a default for locations outside of your regular dev folders
[include]
path = ~/.gitconfig.personal
# IMPORTANT: Yes, the trailing slash is required!
[includeIf "gitdir:~/Development/Personal/"]
path = ~/.gitconfig.personal
[includeIf "gitdir:~/Development/Work/"]
path = ~/.gitconfig.work
[user]
name = <YOUR NAME>
email = <YOUR MAIN/PERSONAL EMAIL>
signingkey = <YOUR GPG KEY FOR PERSONAL EMAIL>
[user]
name = <YOUR NAME>
email = <YOUR WORK EMAIL>
signingkey = <YOUR GPG KEY FOR WORK EMAIL>
# this switches the host for SSH and therefore also selects desired SSH key
[url "git@github.com-work"]
insteadOf = git@github.com
# ~/.ssh/config
Host github.com
Hostname github.com
User <YOUR GITHUB USERNAME>
IdentityFile <PATH TO YOUR MAIN KEY>
IdentitiesOnly yes
Host github.com-work
Hostname github.com
User <YOUR GITHUB USERNAME>
IdentityFile <PATH TO YOUR WORK KEY>
IdentitiesOnly yes
Host *
PreferredAuthentications publickey
Compression yes
ServerAliveInterval 30
ServerAliveCountMax 9999
VisualHostKey yes
AddKeysToAgent yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment