Menu

GitLab: Require Squash Commits for Pull Requests to the “develop” Branch
📰

GitLab: Require Squash Commits for Pull Requests to the “develop” Branch

DEV Community: cicd·Amir Dhaouadi·about 12 hours ago
#pIpHZCOr
#devtocicd#devto#dev#squash#merge
Reading 0:00
15s threshold

Context

On GitLab, squash enforcement has to go through CI, because the native setting applies to the whole project. In Settings → Merge requests → Squash commits when merging , the Require option would also squash the develop → master release MRs, which must keep their history.

GitLab does have an advantage over GitHub: every MR carries a "Squash commits when merge request is accepted" checkbox, readable in CI through CI_MERGE_REQUEST_SQUASH_ON_MERGE and editable through the API. The three options below rely on jobs that only run for MRs into develop .

Shared prerequisite: enable Pipelines must succeed ( Settings → Merge requests ). Without it, a failed job shows a red cross but does not prevent the merge. Squashing must also be allowed (not set to "Do not allow").

Option 1 — Block when the squash box is unticked

The job reads the checkbox when the pipeline starts and fails if it is not ticked.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.