What are workflow rules and how do they prevent duplicate pipelines?

AdvancedConceptGitLab CI
Answer

A branch with an open merge request can get two pipelines per push: a branch pipeline and a merge request pipeline. Top-level workflow:rules decide whether a pipeline is created at all, so you pick one.

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH

This runs MR pipelines for branches with an open MR, and branch pipelines otherwise.

All CI/CD questions Roadmap: GitLab CI/CD

More on GitLab CI