Setting Remote for Multiple GitHub Accounts on Multiple Devices
Published:
If you install Xcode, need to turn off credential.helper.
Credential-osxkeychain will automatically deal with your key.
We want to do it manually so we can have more than one key.git config --show-origin --get credential.helper file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig osxkeychain vim /Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig
- Go to Keychain Access and remove all key in github.com.
- Generate ssh key in your .ssh. Suppose we name them id_rsa_kenway and id_rsa_cw.
ssh-keygen -t rsa -C "your-email-address"
- Go to your GitHub page setting -> SSH and GPG keys -> New SSH key, paste the public key.
- (Optional) Attach the new key.
(delete all attached key) ssh-add -D (list all attached key) ssh-add -l ssh-add ~/.ssh/id_rsa_aaa ssh-add ~/.ssh/id_rsa_bbb
- Touch file name “config” with the following code snippet.
Host github.com-aaa HostName github.com User git IdentityFile ~/.ssh/id_rsa_aaa Host github.com-bbb HostName github.com User git IdentityFile ~/.ssh/id_rsa_bbb
- Set remote node on local folder.
git config user.name "bbb" git config user.email "bbb@outlook.com" git remote set-url origin git@github.com-aaa:aaa/testkey.git git remote set-url origin git@github.com-bbb:bbb/testkey2.git
- Check your GitHub remote.
git remote -v