Skip to content

Instantly share code, notes, and snippets.

@MikeDabrowski
Last active June 14, 2024 09:10
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 = work@mail.com
	signingkey = /Users/mike/.ssh/work.pub
[gpg]
	format = ssh
[commit]
	gpgsign = true

#[core]
#	sshCommand = ssh -i ~/.ssh/work
[url "git@work.github.com"]
	insteadOf = git@github.com
  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 git@github.com

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