不能从远程仓库 git pull 但可以在 GitHub Actions 中 git clone

问题描述

所以我试图将一个分支从我的一个私有存储库拉入 GitHub Actions,以便我可以修改它并将其推回到该存储库中,但它不会让我这样做。虽然我可以克隆 repo,但由于我需要将修改后的文件推回存储库,这将不起作用。我运行命令的工作流在 ubuntu-latest 上运行。另一件要注意的事情是,当我在我的 Windows 计算机上运行这些相同的命令时,一切都正常运行,但出于某种原因,我不需要令牌或用户名来使链接工作。当我尝试从远程存储库中提取时,出现以下错误

remote: Repository not found.
fatal: repository 'https://github.com/[username]/[repo].git/' not found
Error: Process completed with exit code 1.

但是当我尝试克隆存储库时,该命令成功运行。我运行的命令如下。

我用

创建远程仓库
git remote add repo https://[username]:[token]@github.com/[username]/[repo].git

令牌具有 repo 范围,因此它可以完全访问存储库。为了验证命令是否有效,我运行了

git remote -v

其中显示了我添加的新遥控器,所以我知道它有效。接下来,我尝试使用

从远程仓库中拉出 master 分支
git pull repo master --allow-unrelated-histories

这是我得到错误的地方。克隆命令是

git clone https://[username]:[token]@github.com/[username]/[repo].git

git pull 命令不同,此命令运行成功。

我查看了 Git - remote: Repository not foundGit Clone - Repository not found,但我尝试过的所有答案都没有帮助我。由于命令在我的本地计算机上运行,​​因此很可能不是命令,可能与 GitHub Actions 运行命令或令牌的方式有关。

我做了什么让问题发生

  1. 创建一个私有仓库。
  2. 添加文件、提交、推送等
  3. 创建一个公共存储库。
  4. 添加工作流文件
  5. 创建具有 repo 范围的个人访问令牌。
  6. 在公共存储库中添加一个机密并将其设置为 https://[username]:[token]@github.com/[username]/[private repo].git
  7. 添加命令 git remote add repo ${{ secrets.[secret name] }}git remote -v # To verify that the remote add workedgit pull repo [main/master branch]ls
  8. 提交并推送工作流文件,然后运行工作流。
  9. 打开会话日志查看错误

解决方法

我通过将 .git/config 文件设置为我的本地 .git/config 文件解决了我的问题,这解决了问题。我不知道配置文件的哪一部分导致了错误,但我知道它有问题。