I recently had an issue that looked like this:
- I have a personal project on github.com in which I author commits with my personal GitHub account.
- I have a company project on github.com in which I author with my company account.
I had two separate SSH keys for this, one personal and one company, however, since both projects lived in github.com, doing git pull
or git push
would not know which SSH key to use.
The solution (for macOS): a ~/.ssh/config
file where a new DNS name is created to separate the work vs personal case:
Host github.com-company
HostName github.com
User git
IdentityFile ~/.ssh/id_algorithm_company
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_algorithm_personal
No that i create two aliases here, github.com-company
and github.com-personal
.
Then, set the correct remote url for each project.
For the company project:
git remote set-url origin git@github.com-company:CompanyName/company-project
And for the personal project:
git remote set-url origin git@github.com-personal:domantasjurkus/personal-project
🚀
Top comments (0)