搜索
您的当前位置:首页正文

本地配置多个Git仓库

来源:二三娱乐

工作用到公司的git repo,自己在github、coding有自己的repo,但是是在同一台笔记本上连接
一个ssh证书对应一个仓库,在做相应的配置即可
以公司、GitHub、Coding三个repo为例

创建三份ssh证书

配置repo相应的ssh证书

~/.ssh 目录下新建 config文件 touch ~/config
填写内容如下

#dhms 
host git-server
user shiquan
hostname lan.work.cloud
port 29418
identityfile ~/.ssh/id_rsa_work
KexAlgorithms XXXXXXXXXXXXXXXXXX

#github
Host 
User shixiaoquan
HostName 
IdentityFile ~/.ssh/id_rsa_github

#coding
Host 
User shixioaquan
HostName 
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_coding
  1. ssh 客户端是通过类似 :githubUserName/repName.git 的地址来识别使用本地的哪个私钥的,地址中的 User 是@前面的git, Host 是@后面的。
  2. 如果所有账号的 User 和 Host 都为 git 和 。所以要对User 和 Host 进行配置,让每个账号使用自己的 Host,每个 Host 的域名做 CNAME 解析到 。
  3. 配置了别名之后,新的地址就是:githubUserName/repName.git(在添加远程仓库时使用)。
    这样 ssh 在连接时就可以区别不同的账号了。

填写ssh证书内容到相应的repo

~/.ssh 目录下的 id_rsa_work.pub 、id_rsa_github.pub、id_rsa_coding.pub中的内容填写到相应的repo的ssh配置中

完活儿

Top