首页 > 解决方案 > github cli 多个帐户

问题描述

我正在尝试使用GitHub CLI

到目前为止,我可以使用它在我们公司的 repo 中列出 PR。

gh pr checkout 123问题是当我尝试通过123PR 编号来检查 PR 时。

当我这样做时,我收到此错误:

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

Please make sure you have the correct access rights
and the repository exists.
exit status 128

显示错误是因为它正在尝试使用git@github.com. 但我不使用git@github.com,因为我在 GitHub 上有多个帐户。所以我已经将我的设置.ssh/config为:

Host github.com-companyA
    HostName github.com
    User git
    IdentityFile ~/.ssh/companyA

Host github.com-companyB
    HostName github.com
    User git
    IdentityFile ~/.ssh/companyB

我认为解决方案是修改git@github.comgit@github.com-companyA:foo/bar.git

但我不知道在哪里可以使用 GitHub CLI 对其进行修改。

我在这里的最终目标是检查 PR,在我的本地机器上运行一些测试,然后将 PR 标记为通过或失败。

我可以毫无问题地使用 git 处理项目。我可以推拉就好了。只是我想自动检出 GitHub 上 PR 的分支。我无法控制我的团队如何命名他们的分支。

PS 我工作的公司使用不同的技术,而且两家公司每天都有多个 PR。我只是想要一种自动测试多个 PR 的方法,这样我就不必一个一个地做。两家公司也在使用GitHub Actions.

标签: gitgithubsshgithub-cli

解决方案


我找到了解决方案。

gh pr list有一个标志:

-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format

然后,这将列出所有 PR 以及分支名称。然后我可以grep用来获取分支名称。


推荐阅读