'Select configuration depending on remote url

I have two types of Repositories on the same host with different beginning remote url:

github.com/foo/bar.git
github.com/foo/foo.git

github.com/bar/bar.git
github.com/bar/foo.git

And I want git to automatically select the identity and ssh-key depending on the current remote url. Is this even possible?



Solution 1:[1]

First thanks @torek for your great answer.

I've noticed that I can also just use a shared ssh-key. For example if you work with JetBrains Space as I do you can just upload the ssh-key once for each workspace. Than the URL doesn't really matter the Space-Server decides than what account to use.

That's the solution what I personally now went with.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BierDav