Remix.run Logo
powersnail 3 months ago

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.

TeMPOraL 3 months ago | parent | next [-]

Thank you. The article left me uneasy, in OCD sense, about the solution having more degrees of freedom than it needs. I was wondering how to trim it down to one runtime parameter, and yours is an elegant way to do it.

shaicoleman 3 months ago | parent | prev | next [-]

Please note that includeIf is case sensitive, and the order of precedence is last one wins.

To check if it's working correctly you can run:

    git remote get-url origin
    git config --get user.email
qmmmur 3 months ago | parent | prev [-]

In my experience scripts that expect your remote to be a certain way will break with this approach.

powersnail 3 months ago | parent [-]

I don't really use a lot of script that wraps git; but so far the two things I do use---lazygit and github cli---don't have problems with this approach. Github CLI can identify the correct corresponding repo on Github, and also can choose the right user account associated with this repo if there are more than one authenticated user.

I mean, it seems to me that any script that tries to do something with git remote URL, should deal with any string that git thinks is a valid remote URL. `ssh-host-name:owner/repo` is not exactly an edge case.