Live data from Hacker News

Conditional Git Configuration

blog.scottlowe.org

21–30 of 73 posts

Re: Conditional Git Configuration

#21
post #18

You can also configure multiple ssh keys through Github subdomains in your ssh conf file. While github ignores the subdomain your ssh-client will pick the corresponding ssh key bas d on the used subdomain in your repo url.

So subdomains can be arbitrary and you just manually add them when performing git clone? Will then git push/pull/etc automatically use the fake subdomain you like for this repository?

You can have anything you’d like in your ssh config and it will be treated as a server name for auth and auto completion.

So “work-github” can be a Host entry (with a HostName of github.com) and key A. While “play-github” would use key B.

Re: Conditional Git Configuration

#24
post #8

Nice. For years I've been using [direnv]( https://direnv.net/ ) for this, setting environment variables which git picks up. This looks like a more feature complete equivalent, although to be honest I only really need switching of committer email and the SSH key used.

For the SSH part you can use ~/.ssh/config and it also has conditional stanzas like "Host foo.com" or "Host *.foo.com". Can set username, SSH Key, SSH Agent Socket (I use multiple SSH agents), etc.

Re: Conditional Git Configuration

#25
post #13

Can different .git-credentials files also be loaded conditionally? When one uses https access with multiple accounts....

Do you need multiple files? Since you can store credentials for multipl users and host combinations in the same file.

Re: Conditional Git Configuration

#26

You can also configure multiple ssh keys through Github subdomains in your ssh conf file. While github ignores the subdomain your ssh-client will pick the corresponding ssh key bas d on the used subdomain in your repo url.

This works only under the assumption Github won't change the current DNS setup that happens to work this way. A trivial example would be adding a record for the specific subdomain one used directing it to some completely different IP address. Not something I'd be willing to bet on, especially considering the much cleaner solution from the original post.

Re: Conditional Git Configuration

#27

Do you REALLY use ~/Work/Code/Repos path? even with CDPATH configured I would use lowercase folders. I'm just a console/terminal user :D I wrote about this too https://lesterzone.github.io/blog/2023/01/10/git-work-person... I consider this type of 'tips' hidden gems

MacOS’s case insensitive filesystem makes the point moot, if the OP is on that platform. But it makes me wince too!

Re: Conditional Git Configuration

#28

Do you REALLY use ~/Work/Code/Repos path? even with CDPATH configured I would use lowercase folders. I'm just a console/terminal user :D I wrote about this too https://lesterzone.github.io/blog/2023/01/10/git-work-person... I consider this type of 'tips' hidden gems

MacOS’s case insensitive filesystem makes the point moot, if the OP is on that platform. But it makes me wince too!

Autocomplete can make this moot too

Re: Conditional Git Configuration

#29

You can also configure multiple ssh keys through Github subdomains in your ssh conf file. While github ignores the subdomain your ssh-client will pick the corresponding ssh key bas d on the used subdomain in your repo url.

Do you mean a host alias in your SSH config (e.g. `Host your-github-alias` or configuring a subdomain in for the hostname in the config (e.g. `Hostname something-fake.github.com`)?

Re: Conditional Git Configuration

#30
post #17

Does anyone know what is the equivalent for TortoiseGit in Windows? What path should go into gitdir if the repos are at S:\Repos\ ?

Not an equivalent, but I use "Git Extensions", and am very happy with it.

I think Git on Windows uses forward slashes, but colon is retained, like this:

    directory = C:/Program Files (x86)/MyProject
https://gitextensions.github.io
Post reply on HN