无法在 Windows 10 中使用 Powershell 7.1 中的 git

Unable to use git from Powershell 7.1 in Windows 10

我为 Windows 和 Powershell 7.1 安装了 Git。当我尝试使用 ssh 密钥从 git bash 克隆存储库时,它工作得很好。但是,当我尝试从 Powershell 7.1 执行类似操作时,出现 fatal: Could not read from remote repository 错误。

遵循的步骤

1. PS> Start-Service ssh-agent
2. PS> ssh-add D:\Keys\.ssh\my_private_key (I get identity added message)
3. PS> git clone git@github.com:my-username/my-repo.git

错误信息

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

这意味着 ssh 在该 Powershell 会话中尝试在 %USERPROFILE% 而不是 D:\Keys

处查找 SSH 密钥

检查你的 git bash 如果你有一个 ~/.ssh/config 文件,它会指定用于 Host github.com.
的正确私钥 并检查 ~(即 echo $HOME)在上述 git bash 会话中解析的内容。
如果不应该与 Powershell 会话中的默认 HOME 相同,其中 git 默认为 %USERPROFILE%