【问题标题】:Can't git pull from remote repo but can git clone in GitHub Actions无法从远程仓库 git pull 但可以在 GitHub Actions 中进行 git clone
【发布时间】:2021-05-27 05:01:52
【问题描述】:

所以我试图从我的一个私有存储库中将一个分支拉到 GitHub Actions 中,这样我就可以对其进行修改并将其推送回该存储库,但它不会让我这样做。虽然我可以克隆存储库,但由于我需要将修改后的文件推回存储库,这将不起作用。我运行命令的工作流在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 clone 之后,git pull 在本地存储库中是否正常工作?
  • 不想粗鲁.. 但我希望方括号中没有方括号是真实的
  • @MorisFinkel 是的。
  • “无关历史”错误确实表明这里发生的事情比您在问题中向我们展示的要多。如果您可以从头开始(即删除或重命名本地目录),然后使用导致错误的确切步骤顺序更新您的问题,那将有助于我们为您提供帮助。
  • @MorisFinkel 我试过git remote update 但它给出了与另一行相同的错误error: could not fetch repo

标签: git github ubuntu-18.04 github-actions git-pull


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-01-25
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    • 2017-01-26
    • 2012-02-03
    • 2014-12-22
    • 2018-05-13
    • 2021-02-26
    相关资源
    最近更新 更多