Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active August 15, 2019 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennanMKE/7be9c5d174286a25e6e2a5a7e55bd3b6 to your computer and use it in GitHub Desktop.
Save brennanMKE/7be9c5d174286a25e6e2a5a7e55bd3b6 to your computer and use it in GitHub Desktop.
Multiple Identities for Git

Multiple Identities for Git

Interacting with multiple Git hosts using different identities can be useful when there are many repositories in public and proprietary locations.

The includeIf option can be used as a conditional include for a path so that your repos in a GitHub path use your GitHub identity while other locations can use your work identity. In your ~/.gitconfig add the following section.

[includeIf "gitdir:~/Documents/GitHub/**"]
	path = ~/Documents/GitHub/.gitconfig

Then add ~/Documents/GitHub/.gitconfig for that unique configuration.

[user]
	email = linus@gmail.com
	name = Linus

Next your SSH key for GitHub should be unique from your work identity so create a key for that purpose using the same email address which is your primary with GitHub. For the filename select github_rsa instead of the default of id_rsa which is likely already in place.

ssh-keygen -t rsa -b 4096 -C 

Next, update your SSH config at ~/.ssh/config to use this unique SSH key with the host configuration for GitHub.

Host github.com
  UseKeyChain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/github_rsa

Finally, add the new key to your GitHub keys so that your account is authorized.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment