https://gist.github.com/oanhnn/80a89405ab9023894df7
If you have multiple Githib accounts (ex: personal and work) using SSH keys for both accounts can be pretty cumbersome. Following is a simple way to get it done with ssh config.
You need to follow official github guideline to create an ssh keypair, add it to your github account and complete the steps upto "Adding your SSH key to the ssh-agent" in official guide https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
- Make sure you've completed creating and configuring the SSH as mentioned above.
- Open
~/.ssh/config
file in your editor. Create one if a file doesn't exist. - Add a host record as following
Host github.com:<YOUR_GITHUB_USERNAME>
AddKeysToAgent yes
IdentityFile ~/.ssh/<YOUR_SSH_KEY_FILENAME>
Replace <YOUR_GITHUB_USERNAME> with your desired github username (personal or work) Replace <YOUR_SSH_KEY_FILENAME> with your keyfile name in .ssh folder (ex: id_ed25519)
Add a host record for each of the github account you want to maintain.
Git clone would work without any domain name changes to match your ssh condig. Just copy the ssh url and clone away. No special domain names to remember.
git clone github.com:<YOUR_GITHUB_USERNAME>/your-repo.git
This did not work for me at all, while the accepted solutions work fine. You must have additional hidden configuration to make this work.