You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions并行作业推送分支:无需拉取最新如何追加提交?

问题:GitHub Actions并行作业提交代码的竞态条件解决方法

我通过GitHub Actions配置了4个并行运行的作业,它们都会向仓库提交代码,这引发了竞态条件:当其中一个作业率先完成推送后,其他作业推送时会失败并抛出如下错误:

error: failed to push some refs to 'https://github.com/amingilani/canada-amateur-radio-test-bank-archive'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

遗憾的是,git pull无法解决该问题:作业A拉取最新版本后,可能在完成提交推送前,其他作业已经推送了新提交,导致同样的报错。

请问是否存在一种方法,无需以下操作就能将基于过时父引用的提交追加到远程分支顶端:

  • 先拉取当前分支最新版本;
  • 覆盖分支。

已排除的解决方案

针对非GitHub.com的远程仓库,可以使用服务器端钩子处理提交,若提交引用过时则自动更新引用。但由于我使用的是GitHub.com,该方案不适用。

内容的提问来源于stack exchange,提问作者Amin Shah Gilani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:23:13