我希望在同一台电脑上使用两个不同的GitHub账号,所以我为它们都设置了ssh密钥。现在它们都可以正常工作。每次创建新仓库时我不想再次配置我的电子邮件和名称,因此我找到了git的“includeIf”部分。
我正在使用git版本2.37.3。
这是我当前的配置文件。
~/.gitconfig
当我克隆像
然而,当我为我的工作帐户克隆repo,比如
有什么想法为什么这不起作用?
我正在使用git版本2.37.3。
这是我当前的配置文件。
~/.gitconfig
[user]
email = "home@example.com"
name = "Home"
[includeIf "hasconfig:remote.*.url:git@github.com-Work:*/**"]
email = "work@example.com"
name = "Work"
~/.ssh/config
Host github.com-Home
HostName github.com
User git
IdentityFile ~/.ssh/Home
Host github.com-Work
HostName github.com
User git
IdentityFile ~/.ssh/Work
当我克隆像
git clone git@github.com-Home:Home/repo.git
这样的repo并在repo内运行git config user.name
时,我得到了预期的输出Home
。然而,当我为我的工作帐户克隆repo,比如
git clone git@github.com-Work:Work/repo.git
,并在repo内运行git config user.name
时,我得到的是Home
而不是Work
。运行git config remote.origin.url
返回git@github.com-Work:Work/repo.git
。有什么想法为什么这不起作用?
git@github.com-Work:**
的最后一条评论,对于未来的读者而言,这并不足够。它需要是git@github.com-Work:*/**
(请参见本帖中的其他答案)。 - ksgj1