Live data from Hacker News

How I configure my Git identities

benji.dog

11–20 of 113 posts

Re: How I configure my Git identities

#11
post #6
post #2

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?

You can also put that in your includeIf confs. I updated the parent comment

Re: How I configure my Git identities

#13
I use `insteadOf` instead of ssh alias because my workplace use GitLab orgs. So instead of typing the full URL like:

  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

#15
I do something similar, but instead of `insteadOf`, I just clone the repo with `gh-work:org/repo`, and in the git config:

    [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

#16
Shameless plug for a tool I developed in order to easily switch git identities based on projects: https://github.com/cquintana92/git-switch-user

After 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

#17
post #14

Is 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.

If both of your keys are on the same computer they would most likely be compromised simultaneously, or not at all.

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

#18
post #14

Is 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.

Your key cannot be tied to more than one identity, and if you use GitHub Enterprise, your work identity may be restricted from contributing to repos outside of the Enterprise. This is to prevent cloning private code into public spaces. For this reason, you need to have separate keys.

Re: How I configure my Git identities

#19
This 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).

Re: How I configure my Git identities

#20
post #19

This 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).

Privacy for sure. It's no ones business to know how certain accounts are related.
Post reply on HN