Automatically Delete Source Branch After Merge Request is Rejected

Automatically Delete Source Branch After Merge Request is Rejected

Description

Currently, GitLab supports automatic deletion of source branches only when a merge request (MR) is successfully merged. However, there is no option to automatically delete the source branch when a merge request is rejected or closed without merging.

This feature request proposes the addition of an option to automatically delete the source branch when a merge request is closed without being merged, either due to rejection or manual closure.

Use Case

In many workflows, especially in large teams or CI/CD-heavy environments, rejected merge requests often leave behind stale branches. These branches accumulate over time, cluttering the repository and increasing maintenance overhead. Automating their cleanup would:

  • Reduce manual effort for developers and maintainers
  • Keep repositories clean and organized
  • Prevent confusion over outdated or abandoned branches

Proposed Solution

  • Add a project-level and/or user-level setting:
    "Automatically delete source branch when merge request is closed without merging"
  • Optionally, allow this to be overridden per merge request
  • Ensure this action is logged and auditable for traceability

Benefits

  • Cleaner repositories
  • Improved developer experience
  • Reduced risk of mistakenly reviving outdated branches

Related Issues

  • #32783 (closed) – Default to "Delete source branch" on merge (related but only applies to merged MRs)

Thank you for considering this feature!

Edited by 🤖 GitLab Bot 🤖