Git Bash 虽然配置了 Sourcetree,但没有凭据

Git Bash doesn't have the credentials although Sourcetree is configured

我正在使用 Sourcetree,通过 SSH 配置的存储库和所有操作都没有问题,但是通过 Git Bash 我无法执行单个提取或拉:

git fetch
output: Permission denied (publickey).
fatal: Could not read from remote repository.

有没有办法让 Git 使用这个有效的 Sourcetree 配置?

我假设您正在使用 Windows。您可以将 Git 与 OpenSSH 或 Plink (PuTTY) 一起使用。当您在 Sourcetree 中使用 plink 时,您的 SSH 密钥是从 PuTTY(例如 pagent)或您使用 Sourcetree 配置的内容中读取的,当您将 Git Bash 与另一端的 OpenSSH 一起使用时,它们是从读取的~ /.ssh/id_whatever.

要修复它,请在两个客户端中使用相同的 SSH 技术。要在 Sourcetree 中更改它,请转到首选项,并在 Git Bash 中更改它,我认为您需要重新安装它。在安装过程中,系统会询问您是使用 plink 还是 OpenSSH。

在您的机器上生成 SSH 密钥对:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

将 public 密钥复制到存储库:

cat ~/.ssh/id_rsa.pub

运行 cat 将显示 public 键。您还可以使用 SCP 或其他工具将 public 密钥复制过来。

我终于找到了解决方案: