痛点: 一台电脑,多个Github账户。
解决方案: 最简单的办法,通过设置collaborator,让一个账户开发多个项目。所有工作计入这个账户下面。问题,分帐户记账麻烦了。
所以,有了如下方案: 参考链接:docs.github.com/en/account-…
- create SSH key
ssh-keygen -t ed25519 -C "aigenerated1@gmail.com"
ssh-keygen -t ed25519 -C "aigenerated2@gmail.com"
ssh-keygen -t ed25519 -C "aigenerated3@gmail.com"
- Run ssh agent:
这个必须用有admin的powershell。
# start the ssh-agent in the background
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
- Add SSH key to ssh-agent
ssh-add c:/Users/YOU/.ssh/aisshname1
ssh-add c:/Users/YOU/.ssh/aisshname2
ssh-add c:/Users/YOU/.ssh/aisshname3
加完后可以用ssh-add -L查看一下结果。
-
Add the SSH public key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account."
-
.ssh下生成config文件如下:
# Default github account: ai1
Host github.com
HostName github.com
IdentityFile ai1
IdentitiesOnly yes
# Other github account: ai2
Host github.com-ai3
HostName github.com
User git
IdentityFile ai2
# Other github account: ai3
Host github.com-ai3
HostName github.com
IdentityFile ./ai3
IdentitiesOnly yes
- Test the SSH Connection:
$ ssh -T git@github.com
# Attempts to ssh to GitHub
$ ssh -T git@github.com-ai3
$ ssh -T git@github.com-ai2
返回:
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi aiLab1! You've successfully authenticated, but GitHub does not provide shell access.
Hi aiLab3! You've successfully authenticated, but GitHub does not provide shell access.
Hi aiLab2! You've successfully authenticated, but GitHub does not provide shell access.