本地配置多个Git仓库
来源:互联网 发布:mac office 2011 威锋 编辑:程序博客网 时间:2024/05/17 17:16
工作用到公司的git repo,自己在github、coding有自己的repo,但是是在同一台笔记本上连接
一个ssh证书对应一个仓库,在做相应的配置即可
以公司、GitHub、Coding三个repo为例
创建三份ssh证书
1、根据每个repo用到的email生成ssh证书 ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
2、根据不同的repo进行命名,后面需要给每个repo配置证书 Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [XXXXXX(每个repo对应的ssh名称)]
3、输入密码,一般都是直接回车,每次都是免密 Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
重复3次,生成3个ssh证书
分别为: id_rsa_work 、id_rsa_github、id_rsa_coding
位于~/.ssh
目录下(以Mac为例)
配置repo相应的ssh证书
在~/.ssh
目录下新建 config文件 touch ~/.ssh/config
填写内容如下
#dhms host git-serveruser shiquanhostname lan.work.cloudport 29418identityfile ~/.ssh/id_rsa_workKexAlgorithms XXXXXXXXXXXXXXXXXX#githubHost github.comUser shixiaoquanHostName github.comIdentityFile ~/.ssh/id_rsa_github#codingHost git.coding.netUser shixioaquanHostName git.coding.netPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa_coding
原理分析(本段摘自here)
1. ssh 客户端是通过类似 git@github.com:githubUserName/repName.git 的地址来识别使用本地的哪个私钥的,地址中的 User 是@前面的git, Host 是@后面的github.com。
2. 如果所有账号的 User 和 Host 都为 git 和 github.com,那么就只能使用一个私钥。所以要对User 和 Host 进行配置,让每个账号使用自己的 Host,每个 Host 的域名做 CNAME 解析到 github.com,如上面配置中的Host second.github.com。
3. 配置了别名之后,新的地址就是git@second.github.com:githubUserName/repName.git(在添加远程仓库时使用)。
这样 ssh 在连接时就可以区别不同的账号了。
填写ssh证书内容到相应的repo
将~/.ssh
目录下的 id_rsa_work.pub 、id_rsa_github.pub、id_rsa_coding.pub中的内容填写到相应的repo的ssh配置中
完活儿
- 本地配置多个Git仓库
- Git本地项目配置多个远程仓库
- 配置多个git仓库
- Git多个仓库(远程+本地)
- [Linux]本地模拟配置服务器端git仓库
- git一个本地仓库提交到2个账户仓库
- git一个本地仓库提交到2个账户仓库
- 配置多个git远程仓库的ssh-Key切换
- 配置多个git远程仓库的ssh-Key切换
- 配置多个git远程仓库的ssh-Key切换
- 支持多个git仓库的配置方法
- 配置多个git远程仓库的ssh-Key切换
- 合并本地git仓库
- git(本地仓库)
- git删除本地仓库
- git建立本地仓库
- Git本地仓库操作
- 删除git本地仓库
- 抓包工具Fiddler:手机设置代理(IOS)
- 关于iOS企业开发者账号要注意的地方,谨防被骗
- linux环境下gitblit搭建
- 蓝桥杯 题库 基础练习 字母图形
- 第五周——项目三—括号的匹配
- 本地配置多个Git仓库
- 13章,拷贝控制
- python xml解析器
- canvas 实现声呐发声效果
- 【13】MD5编码、Zlib压缩解压缩
- slf4j+log4j使用
- setBackgroudResource或者setBackgroundDrawable导致padding失效的问题
- hdu3435 A new Graph Game
- LeetCode Reverse Integer(反向整数)