无法从远程存储库进行 git 拉取,但可以在 GitHub 操作中 git 克隆



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

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

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

我用

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

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

git remote -v

显示了我添加的新遥控器,所以我知道它工作了。接下来,我尝试用

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

这就是我得到错误的地方。clone命令为

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

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

我已经查看了Git - remote: Repository not found和Git Clone - Repository not found,但是我试过的答案都没有帮助我。由于命令在我的本地计算机上工作,它很可能不是命令,并且可能与GitHub Actions运行命令或令牌的方式有关。

我做了什么使问题发生

  1. 创建私有存储库
  2. 添加文件、提交、推送等
  3. 创建公共存储库。
  4. 添加工作流文件
  5. 创建repo范围的个人访问令牌
  6. 在public repo中添加一个secret,设置为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文件来解决我的问题,并且解决了问题。我不知道配置文件的哪个部分导致错误,但我知道它有问题。

最新更新