Skip to content

Prevent merge commits in pull requests.

License

Notifications You must be signed in to change notification settings

NexusPHP/no-merge-commits

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

git-merge No Merge Commits Action

A Github Action to detect merge commits in pull requests and to prevent them from being merged.

How this works

This action will query GitHub REST API to find all commits in a pull request. After that, this will analyse the response data and check if there are merge commits. If there are any, this action will error and exit.

Usage

name: Detect Merge Commits

on:
  pull_request:

permissions:
  contents: read
  pull-requests: read

jobs:
  test:
    name: Check for merge commits
    runs-on: ubuntu-22.04

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Run test
        uses: NexusPHP/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

You'll also need to add a required status check rule for your action to block merging if it detects merge commits.