主要观点:作者有一篇已起草 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) `代码` - 列表 > 引用。你还可以使用@来通知其他用户。