Skip to content

Instantly share code, notes, and snippets.

@Andrew-SK
Last active March 5, 2022 00:49
Show Gist options
  • Save Andrew-SK/8f099e6c4bfb30dd85261e91b5a4ca25 to your computer and use it in GitHub Desktop.
Save Andrew-SK/8f099e6c4bfb30dd85261e91b5a4ca25 to your computer and use it in GitHub Desktop.
Multiple git identity setup

This is how I set up my git config to assume different identities depending on which directory I'm working in.

In ~/.gitconfig:

[core]
	# sshCommand = ssh -i ~/.ssh/SOME_RSA_PRIVATE_KEY
[user]
	name = Andrew Kemm
[init]
	templatedir = /Users/andrewkemm/.git-template

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

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

# Per client config
# [includeIf "gitdir:~/dev/client/CLIENT_NAME/"]
#	path = ~/dev/client/CLIENT_NAME/.gitconfig

Note the includeIfs associating a directory with another .gitconfig file.

Here is an example of one of those other .gitconfig files:

[core]
	sshCommand = ssh -i ~/.ssh/id_rsa_thoughtworks
[user]
	email = "andrew.kemm@thoughtworks.com"

Here, we specify which rsa token and email address to use.

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