Allow merge trains to reuse SHA for standard merges
What does this MR do and why?
Extends merge trains to reuse the already-validated merge train SHA for standard merge commits, eliminating redundant pipeline runs after merge completion.
Previously, this optimization only applied to fast-forward and semi-linear merge methods. Standard merge commits (the most common merge method) always created a new SHA on the target branch after the merge train pipeline succeeded. This forced teams to:
- Run pipelines again on the new SHA (redundant, since the code is identical)
- Rebuild all artifacts (because the SHA changed, even though the content didn't)
This MR makes merge_from_train_ref? also return true for standard merges when the merge_trains_use_train_ref_for_standard_merges feature flag is enabled. The existing FromTrainRef merge strategy and all its safety checks are reused without modification.
Related issues
Closes #207187 (closed)
Feature flag
merge_trains_use_train_ref_for_standard_merges (beta, disabled by default)
When enabled, standard merge commit merge trains will fast-forward the target branch to the merge train ref SHA instead of creating a new commit. When disabled, behavior is unchanged.
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
How to verify
- Enable the feature flag:
Feature.enable(:merge_trains_use_train_ref_for_standard_merges) - Create a project with Merge commit merge method and merge trains enabled
- Create an MR and add it to the merge train
- After merge, compare SHAs in Rails console:
mr = MergeRequest.last
puts "Merge commit SHA: #{mr.merge_commit_sha}"
puts "Train pipeline SHA: #{mr.merge_train_car&.pipeline&.sha}"
puts "Identical: #{mr.merge_commit_sha == mr.merge_train_car&.pipeline&.sha}"MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

