Skip to main content

Git flow workflow component

The component configures the project to encourage squash commits while still allowing merge requests to preserve their individual commits.

Configure GITLAB_TOKEN with a group service account before allowing the component to update project settings.

Usage​

  • Ensure your projects have a description
  • Set GITLAB_TOKEN as a masked, protected and hidden variable for your group
  • Create and protect your main and develop branches
  • Create GitLab pipeline file .gitlab-ci.yml:

Set branch-name-rule to a GitLab RE2 regular expression to reject new branch names that do not match your convention. An empty value leaves an existing branch-name expression unchanged. The configuration job also enables three push rule checks: the committer email must be verified, the commit author name must match the GitLab account, and the author must be a GitLab user. Project push rules require GitLab Premium or Ultimate and a token with permission to manage them.

Automatic configuration always adds the Git notes workaround to an existing non-empty required commit-message expression. There is no opt-in parameter. An absent expression stays absent, and the negative rule is unchanged.

When the push-rules API is unavailable, the job warns and skips default push-rule checks after confirming project access. An explicit branch-name-rule requires push-rule support. Authentication, permission and other API failures remain errors. See the project push rules API for tier requirements.

Use branch-rules to configure protected branches, access levels, and regular approval rules. Each entry requires branch, allowed-to-merge, and allowed-to-push. Add approvers to select GitLab usernames, group paths that start with /, or the role tokens @@guest, @@reporter, @@developer, @@maintainer, and @@owner. An omitted or empty approvers array selects all project Maintainers and Owners. A wildcard branch such as renovate/* creates an approval rule named renovate.

Set required to a non-negative integer to choose the number of approvals for that branch. When required is omitted, a non-empty approvers list requires one approval; an omitted or empty list selects all Maintainers and Owners but requires zero approvals. Set required: 2 to require two approvals from the selected users or groups.

If reading the approval-rules API returns 403 Forbidden or 404 Not Found, the job warns and skips regular approval-rule configuration, then continues with the remaining workflow settings. Existing approval rules stay unchanged; requested approvers and approval counts are not applied, even when explicitly configured. Check the GitLab tier and token access to enable this configuration. Authentication failures (401), other API errors, and failed rule writes still fail the job.

Use GitLab access level 0 for no access, 30 for Developer, or 40 for Maintainer. Level 60 is available to Administrators on self-managed GitLab. Force pushes are disabled for every configured rule. By default, Maintainers can merge into main, direct pushes to main are disabled, and Developers can push to develop.

When a configured branch contains CODEOWNERS, the component enables Code Owner approval and keeps the regular approval rule. A merge request must satisfy both policies. The component also enables automatic Code Owner reviewer assignment when the GitLab API supports it.

When multiple approval rules are unavailable, GitLab exposes only one user-defined rule. The component reuses that rule for develop only if it already applies project-wide, requires the configured approval count, and has exactly the requested users and groups. It does not delete hidden rules or weaken the visible policy. A non-equivalent rule or an unverifiable capability fails configuration with an actionable diagnostic. Capability verification uses GitLab's licensedFeatureAvailability GraphQL field (GitLab 18.11 or later). API permission failures remain errors; a successful configuration does not change which approval features the project's subscription enforces.

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/codeowners@stable
inputs:
codeowners: |
[Default]
* @@maintainer @@owner
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/workflow-gitflow@stable
inputs:
branch-name-rule: '^(main|develop|(feature|feat|bugfix|fix|hotfix|release|chore|renovate)/[a-z0-9]+(\.[a-z0-9]+)*(-[a-z0-9]+(\.[a-z0-9]+)*)*)$'
branch-rules:
- branch: main
allowed-to-merge: 40
allowed-to-push: 0
approvers:
- alice
- /root-group/reviewers
- "@@owner"
required: 2
- branch: develop
allowed-to-merge: 40
allowed-to-push: 30
approvers:
- "@@maintainer"
- "@@owner"

The example follows the Conventional Branch formal grammar.

Merge request targets​

With GitLab Premium or Ultimate, the configuration job adds target-branch workflows through the native GraphQL API. Use a Maintainer or Owner token. This requires the target-branch API and licensed-feature capability query (GitLab 18.11 or later).

Branches matching feat/* and fix/* target development-branch (default develop). Branches matching hotfix/* target the project default branch. Development branches such as develop or chore/develop match none of these rules, so their release merge requests also use the default branch. Other patterns, including chore/*, are left unchanged by GitFlow. A development branch under feat/* or fix/* is rejected before project configuration because it would target itself.

The job reads every page before changing policy. Existing rules and their relative order are preserved, and repeated runs do not create duplicates. The API exposes no rule priority or reorder operation, so connection order is not used as proof of effective first-match precedence.

Automatic reconciliation supports disjoint patterns only. A rule that could overlap another pattern, or an existing mapping with a different target, causes configuration to fail before changing policy. No existing rule is deleted or recreated. Align the conflicting rules in Settings > Merge requests > Merge request branch workflow, then rerun configuration. Wildcard-overlap checks are conservative; ambiguous patterns require explicit alignment.

An unavailable licensed feature or target-routing API error produces a warning and treats this optional configuration as unavailable in that GitLab version, tier or API context. No further routing writes are attempted and successful routing is not claimed. Earlier confirmed additions, if any, remain in place. Incomplete successful responses, conflicting mappings and ambiguous patterns still fail. Source admission remains enforced independently in CI. Branches without a matching workflow continue to target the default branch. Existing merge requests keep their targets. See GitLab target-branch workflows.

Restrict merge request sources​

Use branch-rules[].source-branches to choose which source branches can merge into each target. validate:gitflow checks every merge request pipeline, including merged-results and merge-train pipelines, independently of autoconfigure-enabled. This is a CI admission check, not a native GitLab protected-branch source setting. It does not change approvals or permissions.

The default GitFlow rule allows the configured development branch and hotfix/* into main. Development targets have no source restriction. An omitted or empty source-branches list allows every source branch. A custom branch-rules array replaces the defaults: include every protection and source rule you need. The development branch is not implicitly exempt from a custom source list.

Patterns are case-sensitive Bash globs matching the full branch name, not regular expressions or shell commands. Every matching target rule applies; overlapping restrictions must all allow the source. Targets without a matching rule are unrestricted. Invalid lists fail validation.

To let Renovate merge directly into main without passing through develop, use a catalog release containing source-branches and add renovate/*:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/workflow-gitflow@stable
inputs:
branch-rules:
- branch: main
allowed-to-merge: 40
allowed-to-push: 0
source-branches:
- develop
- hotfix/*
- renovate/*
- branch: develop
allowed-to-merge: 40
allowed-to-push: 30

Select main as the target of the Renovate merge request. renovate/dependency and hotfix/urgent then pass source validation; feat/change targeting main fails. Renovate still needs the normal successful pipeline and approvals. For a custom development-branch, use that same name in the source and target rules. The default rules expand the configured development branch automatically.

Disable Squash commits when merge request is accepted for development-branch release merges. This requirement still applies when sources are unrestricted. Other admitted sources may use squash. Rerun the MR pipeline after changing its squash setting. The former hotfix input and override variable are removed; configure source admission only through branch-rules.

Customize release rules​

Use release-rules to pass an array of commit analyzer rules to semantic-release. The default [] preserves existing analyzer rules and normal Conventional Commits behavior: features release minor, fixes patch and breaking changes major. For squash merges, check the final commit message and its body.

For example, this consumer can release breaking changes as minor:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/workflow-gitflow@stable
inputs:
release-rules:
- breaking: true
release: minor

Non-empty input replaces releaseRules on the configured commit analyzer, including in an existing .releaserc.json, while preserving its other options and plugins. Commits not matched by a custom rule still use the analyzer's default rules. Other projects retain their defaults unless they opt in. This does not make a breaking API compatible or restrict manually created tags.

Branching​

Roles​

The following roles exist in the scenarios:

  • Developer
    • Creates the respective hot fix, bug fix, or feature branch
    • Implements the respective functionality (=gets hands dirty)
    • Pushes source code to the work branch created above
    • Creates a merge request to the corresponding target branch after successful local testing (see workflow)
  • Maintainer (=Team colleague)
    • Reviews merge requests
    • Decides whether a merge request should trigger a release
    • Merges the merge request (see workflow)

Settings enabled by default​

  • Create development branch if it does not exist
  • Protect main and develop with the configured merge and push access levels
  • Disable force pushes on protected branches
  • Branch rules
  • fast forward merge
  • Pipelines must succeed before merge
  • Merged results pipelines
  • Skipped pipelines are considered successful
  • All discussions must be resolved
  • Allow merge request authors and committers to approve when at most five active human Maintainers and Owners can approve. Prevent both approval types for larger teams.
  • Remove all approvals when commits are added
  • Prevent editing approval rules in merge requests
  • Create a regular approval rule for each configured branch and assign its configured approvers, or all Maintainers and Owners when none are listed. Require the configured required count, defaulting to one for explicit approvers and zero otherwise.
  • With a CODEOWNERS file, also require Code Owner approval and automatically assign matching Code Owners when the GitLab API supports it.
  • Configure merge request targets when the licensed native API is available.

Inputs​

NameDescriptionDefaultType
------------
autoconfigure-enabledEnable or disable the automatic configuration of the pipeline.trueboolean
branch-name-ruleRE2 regular expression that every new branch name must match. An empty value leaves the project push rule unchanged.string
branch-rulesProtected branch, approval, and source-branches rules. An omitted or empty source-branches list allows every source branch. Each rule can assign approvers by username, /group path, or @@role. Access levels are 0 (no access), 30 (Developer), 40 (Maintainer), or 60 (Administrator on self-managed GitLab).[{"branch":"main","allowed-to-merge":40,"allowed-to-push":0,"source-branches":["$CI_WORKFLOW_GITFLOW_DEVELOPMENT_BRANCH","hotfix/*"]},{"branch":"develop","allowed-to-merge":40,"allowed-to-push":30}]array
development-branchThe name of the development branch.developstring
pattern-branch-interruptibleRegex pattern to mark the pipeline as interruptible based on the branch name. Use https://github.com/google/re2/wiki/Syntax/^(feat|fix|hotfix)\//string
pattern-branch-skipRegex pattern to skip the pipeline based on the branch name. Use https://github.com/google/re2/wiki/Syntaxstring
release-rulesCustom commit-analyzer release rules. An empty array preserves the configured analyzer rules and defaults.[]array
rulesThe jobs that this job depends on.[{"if":"$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH","when":"always"},{"when":"never"}]array