一台电脑使用多个git账号

根据账号生成对应的ssh key

ssh-keygen -t rsa -f ~/.ssh/id_rsa_1 -C "account1@qq.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "account2@qq.com"

编辑 ~/.ssh/config 文件

Host github1   // 代号而已 可随便取
         user account1@qq.com
         HostName github.com
         IdentityFile ~/.ssh/id_rsa_1
Host github2
         user account2@qq.com
         HostName github.com
         IdentityFile ~/.ssh/id_rsa_2

将上面创建的专用密钥添加到 ssh-agent 的高速缓存中

ssh-add ~/.ssh/id_rsa_1
ssh-add ~/.ssh/id_rsa_2

将地址的地址改成config里的host,再执行 git clone

账号1
git clone git@github.com:xxx1/xxx1.git 改成 git clone git@github1:xxx1/xxx1.git
账号2
git clone git@github.com:xxx2/xxx2.git 改成 git clone git@github2:xxx2/xxx2.git

如果无法克隆,可先通过https方式克隆下来,再修改 .git/config 里的url地址为ssh地址即可

本地已存在的项目可通过修改项目下 .git/config 文件里的url地址

拓展:

1. 查看当前登录账号:
git config user.name

2. 查看当前登录邮箱:
git config user.email

3. 修改当前项目下用户名和邮箱:
git config user.name "Your_username"
git config user.email "Your_email"

4. 全局修改用户名和邮箱:
git config --global user.name "Your_username"
git config --global user.email "Your_email"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值