git - 是否可以为不同的站点设置全局 git 配置?
问题描述
想象一下,你有这个 git 项目文件夹结构:
- /home/user/gitlab
- /home/用户/github
是否可以在一个地方的某个地方定义使用证书的 git auth 逻辑应该为相应路径之一下的所有项目配置?也许还有不同的用户签名?
解决方案
对于访问:您可以使用您的~/.ssh/config
文件为不同的服务器设置不同的密钥。
# in your ~/.ssh/config file :
Host github.com
IdentityFile path/to/github_key
Host gitlab.com
IdentityFile path/to/gitlab_key
设置后,与github.com
(resp. gitlab.com
) 的任何 ssh 交互 - 例如 : git clone git@github.com:repo
, git fetch
, git push
... - 默认情况下将使用github_key
(resp. gitlab_key
)。
对于git
配置参数(例如:user.name
和user.email
),您可以按照@choroba 的建议使用includeIf
部分(链接到文档):
# in your .gitconfig file :
[includeIf "gitdir:~/github/**"]
path = ~/path/to/github_conf_file
[includeIf "gitdir:~/gitlab/**"]
path = ~/path/to/gitlab_conf_file
并在和中设置user.name
和user.email
值。github_conf_file
gitlab_conf_file
推荐阅读
- python - 如何清除/删除频道中特定用户的消息
- java - 列表有值但没有显示在浏览器或邮递员中,它显示为空白条目
- html - CSS 过渡不透明度适用于 0 到 1,但不适用于 1 到 0
- java - 代码在我输入后按回车之前执行
- python - python - 如何在不停止主线程的情况下运行后台线程
- sql - 数据库 | Postgres | 如何检查 IP 是否在 IP 列表或范围中
- python - 从同名的html获取json
- c# - 你能通过一个 IEnumerable
并检索类型? - delphi - TINiFile.WriteBinaryStream 创建异常
- ios - 如何删除 UITableViewController 中显示为弹出框的行