If you are in a situation like mine, you have personal projects on Github, but you are also part of corporate team which has private repositories, and they require you to go through single sign-on.
Authenticating to a GitHub organization with SAML single sign-on - GitHub Help
You can access an organization that uses SAML single sign-on (SSO) by authenticating through an identity provider…
When you go through SAML SSO, you basically need to give the SSH key you are using SSO capabilities.
Authorizing an SSH key for use with a SAML single sign-on organization - GitHub Help
To use an SSH key with an organization that uses SAML single sign-on, you must first authorize the key.
You could do this with the SSH key that you are already using for your personal projects, which is totally fine, but I really would like to keep my work and non-work credentials separate.
I mean, I really don’t want to screw up, so I’d like to play it safe.
So then I basically have to differentiate between these two:
git clone firstname.lastname@example.org:work-project/work-repository.git git clone email@example.com:lestrrat/personal-repository.git
and provide separate identities depending on the path.
Initially I thought that this would be simple enough using
.git/config but it turned out harder than I thought.
After a few attempts, I came up with this: Use
smartcd (or its alternatives like
direnv) in the non-default project, which in my case is
work-project, and just specify this environment variable.
GIT_SSH_COMMAND="ssh -i ~/.ssh/your_work_identify_file"
And that’s it! These tools automatically sets up different environments depending on the directory that are currently working on, and in git’s case it works out perfectly.
pecoto switch directories, and it works like a charm.