git - 如何在 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
是个人访问令牌并具有所有可能的权限。
是什么赋予了?
解决方案
不确定你是否能够解决这个问题,但我想我会为未来遇到同样问题的人发布一个潜在的解决方案,就像我一样。我遇到了同样的问题,最终证明是缺乏编辑权限在我试图推动的回购上。remote: Repository not found.
不幸的是,来自 GitHub (clone
回购并具有对其的读取权限-混淆的意义何在?对于已通过身份验证的用户而言,这显然是一个授权问题 ♂️)。无论哪种方式 - 我都能够通过获得对 repo 的写访问权来解决这个问题。获得所需权限后 - 我能够成功推送到该仓库。
推荐阅读
- python - 如何检查日期时间是否在 %d/%m/%Y 以及它是否大于某个日期时间
- google-chrome - Chrome 扩展:查看 PDF 时注入内容脚本
- javascript - Filesaver.js:如何编写包含二进制数据的 blob?
- photoshop - 在 Photoshop 中向上或向下移动图层
- parameters - 如何将文件或目录路径作为 REST API 参数传递给 Fastify 端点
- javascript - 将整数列表发送到 REST API 会引发 415(不支持的媒体类型)
- python - 错误:对象可以在同一个线程中使用
- javascript - 在 2 个 svg rects 之间绘制动态线
- django - Django - 在管理员工作中显示历史记录,但仅在管理员中发生操作时显示
- javascript - 为什么我的函数不会绘制多个砖块?