git设置多账户多仓库

针对于工作环境远程仓库和开源仓库如gitee,github分开账户管理
具体步骤如下:

一、公钥加密

cd ~/.ssh
ssh-keygen -t rsa -C "xxx@qq.com"
#设置文件名,自动生成私钥和公钥(.pub)
Enter file in which to save the key (/c/Users/icecr/.ssh/id_rsa): id_rsa_gitee
#将ssh key添加到SSH agent中 
ssh-add ~/.ssh/id_rsa_gitee

如果报错 执行ssh-add时出现Could not open a connection to your authentication agent, 则执行

ssh-agent bash

二、在~/.ssh下新增config文件

host gitee.com
    Hostname gitee.com
    User 用户名
    IdentityFile ~/.ssh/id_rsa_gitee

host gitlab.com
    Hostname gitlab.com
    User 用户名
    IdentityFile ~/.ssh/id_rsa

三、具体到某个项目下,可以设置该项目的git配置,配置信息在项目目录下.git/config

进入项目/.git目录下执行以下命令:

git config user.name icecrea
git config user.email xxxx@qq.com

四、将ssh公钥设置到远程仓库

公钥存储在~/.ssh/id_rsa_gitee.pub

五、测试连接

ssh -T git@gitee.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值