I have a company GitHub account and a personal GitHub account. Recently, I want to use my personal GitHub account on my company Macbook. I already have the company GitHub account set up on the company Macbook long time ago. But now I have no idea how I can switch to my personal GitHub account on some of my projects while keep using the company GitHub account on those company projects' repositories.
I want to be able to freely use both personal and company GitHub accounts on the same Macbook device.
you can try below procedures:
Open terminal in Macbook
cd ~/.ssh
ssh-keygen -t rsa -C "your github email" -f "my-personal-github"
eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/my-personal-github
pbcopy < ~/.ssh/my-personal-github.pub
Then login to your GitHub account and go to section "SSH and GPG Keys", click on "New SSH Key" and then add the public key just copied by the pbcopy command.
touch ~/.ssh/config
Add the following content to the file
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/my-personal-github
Then, to use the new config, we clone the GitHub repo by command
git clone [email protected]:[your GitHub ID]/[Your Repo ID].git
git remote add "origin" [email protected]:[your GitHub ID]/[Your Repo ID].git
Hope this can help!