首页 > 解决方案 > 如何在 github 操作中推送到另一个存储库?

问题描述

在 Github Actions 中,我试图对与工作流所属的存储库不同的存储库进行一些更改。请参阅此代码:

      - name: Generate API module
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |

          git clone https://user:$GITHUB_TOKEN@github.com/owner/my-repo # This works

          cd my-repo
          git config user.name "user"
          git config user.email "dev@example.com"

          git checkout -b api-version-$COMMIT

          touch new-file.sh
          git add new-file.sh
          git commit -m "Add new file"

          git remote -v # Prints:
          # origin ***github.com/owner/my-repo.git (fetch)
          # origin ***github.com/owner/my-repo.git (push)

          git push --set-upstream origin api-version-$COMMIT # This does not work
          git push --set-upstream https://user:$GITHUB_TOKEN@github.com/owner/my-repo api-version-$COMMIT # This does not work either

我可以很好地克隆所有者/存储库。我可以签出新分支,添加文件并提交更改。当我尝试将更改推送到上游时会出现问题。这根本不起作用,我得到这个错误:

remote: Repository not found.
fatal: repository 'https://github.com/owner/my-repo/' not found

我只是猜测它与身份验证有关。这GITHUB_TOKEN是个人访问令牌并具有所有可能的权限。

是什么赋予了?

标签: gitgithub-actions

解决方案


不确定你是否能够解决这个问题,但我想我会为未来遇到同样问题的人发布一个潜在的解决方案,就像我一样。我遇到了同样的问题,最终证明是缺乏编辑权限在我试图推动的回购上。remote: Repository not found.不幸的是,来自 GitHub (clone回购并具有对其的读取权限-混淆的意义何在?对于已通过身份验证的用户而言,这显然是一个授权问题 ‍♂️)。无论哪种方式 - 我都能够通过获得对 repo 的写访问权来解决这个问题。获得所需权限后 - 我能够成功推送到该仓库。


推荐阅读