.gitconfig的多仓库配置

.gitconfig的多仓库配置

Tags
一些小技巧
Git
config
Published
Published May 6, 2022
Author
wapeasy

背景:

有了多个ssh key,所以就会产生多个git仓库 为了不让.gitconfig里面看上去那么乱,并且还需要区分提交用户和网络配置,所以将配置文件分开最完美

配置前:

  • 配置会用到gitincludeif功能,所以git的版本需要升级到2.13以后的版本。
  • 配置的原理是通过全局的.gitconfig文件索引到自定义的gitcofig文件

配置方法:

全局的.gitconfig文件配置
[includeif "gitdir:D:/SourceCode/www/"] path = ~/.gitconfig_per [includeif "gitdir:D:/SourceCode/workspace/"] path = ~/.gitconfig_job
个体代码库的配置.gitconfig_per
[user] email = 你的github邮箱 name = 你的github用户名 [http "https://github.com"] proxy = 你的代理 sslVerify = false [https "https://github.com"] proxy = 你的代理 sslVerify = false [url "https://github.com"] insteadOf = git://github.com
个体代码库的配置.gitconfig_job
[user] email = 你的工作邮箱 name = 你的工作用户名

一些注意的地方:

  • gitdir的路径注意写法,/和正常的win的绝对路径不一样,需要注意
  • path后的新建配置文件路径需要加'',在win环境里如果加''会索引不到,路径不要写绝对路径,可以直接写相对路径,按照我给出的举例写法即可