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.
it's much easier to have a conditional git config in ~/.gitconfig that modifies the git ssh command to explicitly use a different ssh key.