gitconfig 忽略 includeIf

标签 git github git-config

我正在尝试设置我的 git 配置,以便我可以使用工作环境和个人环境。

这是我的 ~.gitconfig 文件的内容(碰巧 work 和 private 在 github 上):

 [url "git@github.com:"]
    insteadOf = https://github.com/
 [core]
    editor = vim
 [includeIf "gitdir:~/go/src/github.com/work/"]
    path = ~/.gitconfig-work
 [includeIf "gitdir:~/go/src/github.com/fzd/"]
    path = ~/.gitconfig-private

这是两个文件的内容:

> cat ~/.gitconfig-work
[user]
    email = workerID@company.com
    name = realname
    signingkey = 454684684654...
[commit]
    gpgSign = true

> cat ~/.gitconfig-private
[user]
    email = fzd@email.com
    name = fzd

现在让我们漫游到这些目录之一:

> cd ~/go/src/github.com/work/
> git config --get user.email  
> 

> cd ~/go/src/github.com/fzd/
> git config --get user.name
> 

以上均未返回字符串。

我期待它能工作(它会解决我麻烦的 git 配置)。

现在,“有趣”的部分:这个配置最初是我的工作配置,只有工作设置正确。 当我尝试从 github 克隆一个 repo 时,无论我身在何处,它都在使用我的工作设置(自从我尝试摆弄 git 以来我还没有重新启动——我想这还不值得)。

谁能告诉我我的配置有什么问题?为什么要使用工作参数? git 配置上有一种缓存吗?

[编辑] 以下是我的 ~/.ssh/config 文件的内容:

 Host github.com
     Hostname ssh.github.com
     Port 443
 
 Host *
  ServerAliveInterval 10
  AddKeysToAgent yes
  IgnoreUnknown UseKeychain
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519_work

我确实有一个私有(private)存储库的 key 对,我不完全确定如何在此处同时拥有这两个 key 。可能类似于 this .

最佳答案

includeIf 仅适用于 ~/go/src/github.com/work/~/go/下的repositories src/github.com/fzd/ 但不在非 repo 目录中。

测试:

cd ~/go/src/github.com/work/<some-repo>
git config --get user.email

关于gitconfig 忽略 includeIf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71473679/

相关文章:

git - 在 Git 中使用 receive.denyCurrentBranch 有什么后果?

git - 如何在带有别名的gitconfig中正确使用bash变量

git - git reset --hard 后留下的未暂存更改

git - pull 请求是 Git 的一部分,还是 GitHub、Gerrit 和 Atlassian Stash 等工具的一项功能?

git - 在一个仓库 Github 中添加多个项目

github - 如何通过 github 找到我的组织 ID?

git - 推送时使用的是本地版本的git还是远程版本的git?

git - 设置远程使用指定端口进行 ssh

git - 重用 Git 子模块的子模块

git - 致命的 : 'origin' does not appear to be a git repository