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

GitHub Actions自动创建PR失败求助:dev分支推送未生成PR

Fix: GitHub Actions Not Creating PR from dev to master on Push

The Problem

You set up a GitHub Actions workflow to automatically create a PR from dev to master (with assigned reviewers) whenever code is pushed to dev. The workflow runs successfully, but no PR gets created. The logs show:

Branch 'create-pull-request/patch' is not ahead of base 'master' and will not be created

Why This Happens

The peter-evans/create-pull-request@v2.8.0 action you’re using has a specific default behavior: it creates a temporary branch (like create-pull-request/patch), rebases your dev branch commits onto master, then checks if this temp branch has new commits compared to master. If dev doesn’t have any changes that master doesn’t already have (or the push didn’t add new unique commits), it won’t create a PR.

Also, the branch: dev parameter in your original config doesn’t work how you might expect—this action is designed to work with auto-generated temp branches by default, not directly use your existing dev branch as the PR source.

Solutions

If your goal is simply to open a PR from dev to master every time you push, using the GitHub CLI (gh) is more straightforward than the create-pull-request action. Here’s how to update your workflow:

name: Auto-Create PR (dev → master)
on:
  push:
    branches: [ dev ]
jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4
      
      - name: Create PR via GitHub CLI
        run: |
          gh pr create \
            --base master \
            --head dev \
            --title "Automated PR: dev → master" \
            --body "This PR was automatically created when code was pushed to the dev branch." \
            --labels "automated pr" \
            --assignee assignee1 \
            --reviewer reviewer1,reviewer2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Note: Make sure the default GITHUB_TOKEN has permission to create PRs. For public repos, this is enabled by default; for private repos, go to your repo’s Settings → Actions → General and confirm "Workflow permissions" is set to "Read and write permissions".

Option 2: Adjust the create-pull-request Action Settings

If you want to stick with the peter-evans action, update the config to point directly to dev as the PR source, and fix outdated settings:

name: Create Pull Request
on:
  push:
    branches: [ dev ]
jobs:
  createPullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Pull full repo history to properly compare branch differences
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v5 # Upgrade to the latest version (v2 is outdated)
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Automated PR from dev to master
          title: 'Automated PR: dev → master'
          labels: automated pr
          assignees: assignee1
          reviewers: reviewer1, reviewer2
          draft: false
          base: master
          head: dev # Explicitly set the PR source branch to dev
          branch: dev # Match this to the head branch so the action uses your existing dev branch

Key fixes here:

  • Upgrading to v5 of the action (old versions had branch-handling bugs)
  • Adding fetch-depth: 0 to ensure the action can see all branch history
  • Setting head: dev to tell the action to use your dev branch as the PR source

Quick Checks to Validate

  • Make sure dev has commits that aren’t on master—if there’s no difference, no PR will be created (this is expected behavior).
  • Test with a new commit to dev to trigger the workflow and confirm the PR is generated.
  • Double-check your repo’s workflow permissions to ensure the GITHUB_TOKEN can create PRs and assign reviewers.

内容的提问来源于stack exchange,提问作者BlimBlam

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 21:17:38