you don't have to mess with ~/.ssh/config Just put this in your ~/.gitconfig (or ~/.config/git/personal as in the article) [core] sshCommand = /usr/bin/ssh -o IdentitiesOnly=yes -i ~/.ssh/IdentityFile2 -a This makes submodules easy without the `insteadOf`
And if you have more than one SSH identity?
How I configure my Git identities
11–20 of 113 posts
Re: How I configure my Git identities
#12So glad I clicked on this link. I was already doing the `includeIf: "gitdir"` thing to separate work and personal stuff, but `hasconfig:remote` is a total game-changer.
Re: How I configure my Git identities
#13 git clone gitlab.com/acme-corp/project-name
I could use: git clone work:project-name
But this kinda broke `includeIf` since it store the `insteadOf` remote url directly. I then had to convert existing repositories to use the `insteadOf` url.I wrote a little bit about it here: https://bentinata.com/log/git-insteadof-includeif
Re: How I configure my Git identities
#14The private bits are all in the same place: if one is compromised, so are the rest.
Re: How I configure my Git identities
#15 [includeIf "hasconfig:remote.*.url:gh-work:**/**"]
path = ~/.gitconfig.d/gh-work.inc
So, any git repo cloned with the ssh identity defined under `gh-work` will take on the config of `gh-work.inc`, which includes the git identity, and also the same signing key as in the ssh config.Essentially, the name `gh-work` becomes the distinguishing element in both my ssh identity and my git identity, and I find this easier to think about.
Re: How I configure my Git identities
#16After configuring the identities you just need to run
$ git su Personal
$ git su Work
And all the identity configuration (email, name, SSH key and optionally PGP key) will be set up into the repo's .git/config file.Saved me a ton of time.
Re: How I configure my Git identities
#17Is there a risk with not using different keys for work and personal? The private bits are all in the same place: if one is compromised, so are the rest.
However if you're worried about this then you should probably be using a hardware token anyway - something that supports SSH authentication via FIDO2, GPG, or smart card interface.
Re: How I configure my Git identities
#18Is there a risk with not using different keys for work and personal? The private bits are all in the same place: if one is compromised, so are the rest.
Re: How I configure my Git identities
#19One thing though: what’s the point of using separate keys for work/personal/github/gitlab? I fail to see a practical and security advantage over using one key (per workstation).
Re: How I configure my Git identities
#20This post is a great reference of what’s possible with git config wrt includes/remotes, and I’m sure I’ll be getting back to it. One thing though: what’s the point of using separate keys for work/personal/github/gitlab? I fail to see a practical and security advantage over using one key (per workstation).