Disable "Squash and merge" on some specific branches #10809
Replies: 377 comments 95 replies
-
+1. same exact use case. there are so many options in the "Branch protection rules" I was surprised this wasn't one of them (and also it seems like a good place to hang this feature) |
Beta Was this translation helpful? Give feedback.
-
+1 We want to enforce We have resorted to using memes to try to get everyone to remember to apply the right merge type for the right branch:
|
Beta Was this translation helpful? Give feedback.
-
+1 This seems like a pretty normal use case. |
Beta Was this translation helpful? Give feedback.
-
+1 I really would like to set merging strategies per branch – same way as it is possible now for the whole repository. For benchmark: Azure Repositories does it really well. Other things are far worse, but this is where they're superior in my opinion. |
Beta Was this translation helpful? Give feedback.
-
+1 Our team would like to configure merge strategy for each branch separately as well |
Beta Was this translation helpful? Give feedback.
-
Yes, this keeps biting us as well. GitHub... please hear our cries! |
Beta Was this translation helpful? Give feedback.
-
Branch protection rules appears to be the right place to define this. Github, please reach out if you are looking for beta testers for this feature request. ;-) |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot those who showed interests in this feature request! |
Beta Was this translation helpful? Give feedback.
-
This would be a great feature. The number of times people on our team accidentally squash merge to master, then I'm forced to resolve conflicts on develop...urgh! |
Beta Was this translation helpful? Give feedback.
-
It persists the button as whatever last one you used, which makes this really easy to flub. Then the poor sucker who has to do the next merge into the deploy branch has a mess to unravel. |
Beta Was this translation helpful? Give feedback.
-
Yeah, this feature would be great. |
Beta Was this translation helpful? Give feedback.
-
yes please allow specify merge strategy per branch protection rule... |
Beta Was this translation helpful? Give feedback.
-
+1 exact same use case. Surprising that it hasn't been considered for so long. |
Beta Was this translation helpful? Give feedback.
-
+1. We've been promoting branches associated with environments so dev->stg->prod and it would be great to enforce squash merge into dev and disable squash merge for stg and prod. |
Beta Was this translation helpful? Give feedback.
-
+1 need this |
Beta Was this translation helpful? Give feedback.
-
Until requested feature is implemented, a workaround for our team was to merge to protected branches through GitHub Actions workflow. merge_validation.ymlMerging to protected branches must be done through Github Actions "Automerge" workflow. name: Merge validation
on:
pull_request:
branches:
- 'production'
- 'staging'
jobs:
merge-validation:
runs-on: ubuntu-22.04
steps:
- name: Merge validation
if: github.event_name != 'workflow_dispatch'
run: |
echo "ERROR: Manual merging is not allowed. Use GitHub Actions 'Automerge' workflow."
exit 1 automerge.ymlAutomatically merges source to target branch and pushes to remote -> once commit is pushed to remote, regular deploy workflow can be triggered name: Automerge
on:
# Manually trigger workflow runs
workflow_dispatch:
inputs:
targetBranch:
type: choice
description: Select target branch (source branch is auto-detected)
required: true
default: "staging"
options:
- "production"
- "staging"
jobs:
merge:
runs-on: ubuntu-22.04
steps:
- name: Check out code with token
uses: actions/checkout@v4
with:
ref: ${{ inputs.targetBranch }}
token: ${{ secrets.PAT }}
- name: Automerge
run: |
sourceBranch=development
if [[ "${{ inputs.targetBranch }}" == "staging" ]];
then
sourceBranch=development
elif [[ "${{ inputs.targetBranch }}" == "production" ]];
then
sourceBranch=staging
fi
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions Bot"
git config pull.rebase false
git pull origin $sourceBranch
git push origin $targetBranch |
Beta Was this translation helpful? Give feedback.
-
Migrating from Azure DevOps to GitHub and surprised to see this not supported. +1 |
Beta Was this translation helpful? Give feedback.
-
Wild that this has taken so long. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm now building a deploy workflow for a monorepo, and trying to set up a CI workflow triggered by a push to a special branch (like
production
) for deployment. We currently merge regular PRs to the main branch using "Squash and merge" by enabling "Require linear history" option, and merging "deploy" PRs to the production branch with "Create a merge commit" in order to avoid unexpected divergent.It works, but not perfect because "Squash and merge" button is present when merging a PR to the production branch.
As far as I searched, I couldn't find a good way to enforce developers to use "Create a merge commit".
Is there a good way to achieve that?
So far, I could find a stackoverflow saying it's not possible.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions