Git通过配置config维护多个账号,区分个人账号和公司账号

1. 生成多个不同的sshkey秘钥

1.1 生成新的id_rsa公钥(个人)

ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa

1.2 生成新的tc_pub公钥(公司)

ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/tc_pub

2. 在.ssh目录下新建一个config(无后缀文件)

(.ssh目录一般在C:/Users/xxx/.ssh目录)

# 个人account

Host github.com
HostName github.com
User CoderBruis

IdentityFile D:\MyConfiguration\TCLDUSER\.ssh\id_rsa
IdentitiesOnly yes

# 公司account

Host git.xxx.com
HostName git.xxx.com
User luohaiyang

IdentityFile D:\MyConfiguration\TCLDUSER\.ssh\tc_pub
IdentitiesOnly yes

3. 使用时不能设置全局username和email

取消设置全局的username和email

git config --global --unset user.name
git config --global --unset user.email

4. 在repo中使用不同的用户进行操作,进入repo目录后,需要先设置username和email,然后再进行其他操作

git config user.name CoderBruis

git config user.email "youemail"

然后查看该repo目录下,你的用户名和密码信息:

git config user.name

git config user.password

100. 命令总结

查看用户名 :git config user.name
查看密码: git config user.password
查看邮箱:git config user.email
测试ssh:ssh -T git@github.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值