美文网首页
Mac一台电脑配置多个git账号

Mac一台电脑配置多个git账号

作者: 萌萌哒小鼠儿 | 来源:发表于2019-04-15 16:50 被阅读0次

1 设置账号


git cofig --global user.name "lbhwjs1993"

git config --global user.email "1459247241@qq.com"

2 生成ssh密钥

ssh-keygen -t rsa -C "1459247241@qq.com"

3设置别名

生成ssh密钥命令执行时,会弹出设置密钥文件别名的框

设置别名

设置密码

4新密钥添加到ssh-agent


ssh-agent -s

ssh-add ~/.ssh/id_rsa_myself

5在config文件中配置git仓库,退出保存

cd ~/.ssh

vim config

代码块


Host jmp

HostName jumper.sankuai.com

IdentityFile ~/.ssh/id_rsa

User libinghua

IdentitiesOnly yes

ControlPersist yes

ControlMaster auto

ControlPath ~/.ssh/master-%r@%h:%p

#自己Git仓库

Host lbhwjs1993

HostName github.com

User libinghua

IdentityFile ~/.ssh/id_rsa_myself

6将id_rsa_myself.pub中的内容添加到gitlab帐号下的SSH Key。

截图展示

7添加SSH Key 后进行测试是否连接成功

ssh -T git@github.com

8推动流程

本地打开代码文件夹

例子:


cd journalcode

git init

git add .

git remote add lbh git@github.com:lbhwjs1993/journalcode.git  (仓库需要有该文件)

git push -u lbh master

后续就不需要改动

如果git remote add lbh错误的话

git remote rm lbh删除上一个错误的连接

git remote add lbh git@github.com:lbhwjs1993/journalcode.git 重新建立一遍连接

9查看全局用户名

git config --list

重置全局用户名

如果 git push -u lbh master 报错


可以执行步骤234,再执行步骤8

相关文章

网友评论

      本文标题:Mac一台电脑配置多个git账号

      本文链接:https://www.haomeiwen.com/subject/lqqpwqtx.html