Multiple Git Ssh Config Single Machine


Published:   October 20, 2021

Tags:
Ref: https://dev.to/arnellebalane/setting-up-multiple-github-accounts-the-nicer-way-1m5m

To use multiple github account on same hosts, and using ssh to push and pull the repo. We have multiple tricks

Used host trick before, but while setting up again and looking for documentation found this neat way using gitconfig.

We can have to first set .gitconfig file in home directory.

1
2
3
4
5
[includeIf "gitdir:~/workspace/work/"]
    path = ./.gitconfig-work

[includeIf "gitdir:~/workspace/personal/"]
    path = ./.gitconfig-personal

.gitconfig-work file

1
2
3
4
[user]
	email = "sumit.murari@work.com"
[core]
	sshCommand = "ssh -i ~/.ssh/id_rsa"

.gitconfig-personal file

1
2
3
4
[user]
	email = "murari.sumit@fastmail.com"
[core]
	sshCommand = "ssh -i ~/.ssh/personal-ecdsa"


Let me know if you have any questions or comments.
It will help me to improve/learn.


< Older   Further Reading   Newer >