主要观点:作者有一篇已起草 3 年的帖子,介绍了通过git
的includeIf
和hasconfig:remote.*.url:
等配置来根据不同条件配置git
及SSH
密钥,以更好地管理多个git
身份和远程仓库。
关键信息:
includeIf
可根据条件包含特定文件,如[includeIf "gitdir:~/code/**"] path = ~/.config/git/personal
。hasconfig:remote.*.url:
可根据当前工作目录的远程 URL 配置git
,如[includeIf "hasconfig:remote.*.url:git@github.com:*/**"] path = ~/.config/git/config-gh
。~/.ssh/config
可配置SSH
密钥,如Host gitlab.com User git IdentityFile ~/.ssh/gitlab.id_ed25519
,为不同Host
设置不同IdentityFile
。- 可通过
[url "gh-work:orgname"] insteadOf = git@github.com:orgname
在git
配置中使用不同的Host
来替换远程 URL。
重要细节: includeIf
中配置的顺序很重要,后匹配的配置会覆盖先匹配的,如github.com:orgname/**
要在github:*/**
之后。- 对于
ssh-agent
的配置,可在~/.ssh/config
的IdentityFile
行后添加IdentitiesOnly yes
。
参考文献:列举了多个相关文章的链接。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。