The only way I succeededd so far is to employ SSH keys.
Navigate to ~/.ssh and open up the config file. By default, it should look something like this:
Host *
AddKeysToAgent yes
UseKeyChain yes
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes- In order for your Mac to be identified by two different GitHub accounts, you'll need to create SSH key pairs for each account.
-
run
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -
This will prompt "Enter a file in which to save the key". The default suggested filename would be
id_rsa. Remember to name the new file differently if you have any existing one, eg.user-1. This will generate a private and public key,user-1anduser-1.pub, respectively.
-
Register the contents of the public key, e.g
user-1.pub, into the respective GitHub accounts. Follow the steps here to do so -
Head back over to the SSH
configfile at~/.sshand amend accordingly to:
>#user1 account Host github.com-user1 HostName github.com User git IdentityFile ~/.ssh/github-user1 IdentitiesOnly yes #user2 account Host github.com-user2 HostName github.com User git IdentityFile ~/.ssh/github-user2 IdentitiesOnly yesReplace
user1oruser2with your GitHub usernames
- Go ahead to git clone the respective github account
git clone git@github.com-user1:user1/your-repo-name.git your-repo-name_user1