Skip to content

Instantly share code, notes, and snippets.

@MikeDabrowski
Last active November 3, 2024 11:24
Show Gist options
  • Save MikeDabrowski/3b6d93caf0d451f8661b7d6a8c243688 to your computer and use it in GitHub Desktop.
Save MikeDabrowski/3b6d93caf0d451f8661b7d6a8c243688 to your computer and use it in GitHub Desktop.
Git/ssh multiple accounts
  1. Create ssh keys for each account
  2. add them with ssh-add
  3. create .gitconfigs for each account
[user]
	name = MikeDabrowski-Work
	email = [email protected]
	signingkey = /Users/mike/.ssh/work.pub
[gpg]
	format = ssh
[commit]
	gpgsign = true

#[core]
#	sshCommand = ssh -i ~/.ssh/work
[url "[email protected]"]
	insteadOf = [email protected]
  1. in main gitconfig do ifs
[includeIf "gitdir:/Users/mike/Projects/Work/"]
  path=~/.gitconfig-work
  1. in main ssh config
Host github.com
  AddKeysToAgent yes
  UseKeychain yes

Host work.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/work
...

the commented lines [core] - this is an alternative, if you want to use it, disregard step 5 and [url...] config lines

https://stackoverflow.com/questions/3225862/multiple-github-accounts-ssh-config/76573859#comment138602167_76573859

Test with ssh -vT [email protected]

@MikeDabrowski
Copy link
Author

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