多github账号的仓库配置

# 为第一个账号生成密钥

ssh-keygen -t ed25519 -C "your_email1@example.com" -f ~/.ssh/id_ed25519_account1

 

# 为第二个账号生成密钥

ssh-keygen -t ed25519 -C "your_email2@example.com" -f ~/.ssh/id_ed25519_account2

# 打开~/.ssh/config配置文件

# 第一个 GitHub 账号

Host github.com-account1
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_account1
    IdentitiesOnly yes

 

# 第二个 GitHub 账号

Host github.com-account2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_account2
    IdentitiesOnly yes

 

# 进入第一个仓库

cd /path/to/repo1
git config user.name "chat0515"
git config user.email "chat50897@gmail.com"

 

# 第一个仓库使用 account1

git remote set-url origin git@github.com-account1:YourName1/repository.git

 

# 测试连接

ssh -T git@github.com-account1
ssh -T git@github.com-account2

 

posted @ 2025-07-29 22:12  JustinBeebor  阅读(12)  评论(0)    收藏  举报