Skip to content

Instantly share code, notes, and snippets.

@raffleberry
Last active November 10, 2024 06:19
Show Gist options
  • Save raffleberry/29392b644456b2057246b4a6c6179785 to your computer and use it in GitHub Desktop.
Save raffleberry/29392b644456b2057246b4a6c6179785 to your computer and use it in GitHub Desktop.
Setup Multiple github accounts and ssh keys

Context

You're Robin and you want to commit as Batman.

~/.gitconfig

[user]
	email = [email protected]
	name = robin
[core]
	sshCommand = ssh -i ~/.ssh/robin_pk

[includeIf "gitdir:/home/user/BatmanSrc/**"]
    path = ~/.gitconfig.batman

~/.gitconfig.batman

[user]
	email = [email protected]
	name = batman
[core]
	sshCommand = ssh -i ~/.ssh/batman_pk

Explanation

Any git commands inside ~/BatmanSrc/ will make it look like you're Batman.

References

https://git-scm.com/docs/git-config#Documentation/git-config.txt-codegitdircode

https://stackoverflow.com/a/78194261/9133262

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