Bitbucket auto-merge: merge a pull request when checks or builds pass
Instead of coming back to press Merge once the last approval or build arrives, you can let Bitbucket merge the pull request for you. Data Center and Cloud both offer this, in different forms: Data Center has auto-merge (from 8.15), which waits for every merge check; Cloud has a merge check, Allow automatic merge when builds pass, which waits only for builds. From Atlassian's Merge a pull request (Data Center), the 8.15 release notes, the Data Center REST reference and Cloud's Suggest or require checks before a merge.
Data Center: auto-merge
- Turn it on: in Project settings or Repository settings, select Auto-merge, then Enable auto-merge. If it is off for the project, a repository first needs Use custom settings. An administrator can switch the feature off for the whole server.
- Ask for it: a clock on the Merge button means auto-merge is available. Choose the merge strategy and commit message as for a normal merge, then select Merge. If every check already passes, it merges at once.
- Who merges: once all merge checks pass, Bitbucket merges on behalf of the user who asked. That user needs write permission on the target repository, and can ask for auto-merge on someone else's pull request.
- Cancel it: Cancel merge at the top right of the pull request. Bitbucket also cancels it by itself, and records why on the pull request and by email, when there are merge conflicts, new code changes are pushed, the target branch changes, merge checks time out, the merge strategy can no longer be used, the user who asked is inactive or lost the permission, or the pull request could not be merged for two weeks (the default, which an administrator can change).
Data Center: the REST API
- The merge call (
POST …/pull-requests/{id}/merge) takes"autoMerge": truein its body, besidestrategyId,messageandversion: it merges immediately when it can, and otherwise sets the pull request to auto-merge when all merge checks pass. With the repository's auto-merge setting off, it answers 403. GET …/pull-requests/{id}/auto-mergereturns the request (its strategy, commit message, source commit and when it was made);DELETEon the same address cancels it.…/repos/{slug}/settings/auto-mergeand…/projects/{key}/settings/auto-mergeread and change the setting.
Cloud: Allow automatic merge when builds pass
- A merge check in a branch restriction (Repository settings > Branch restrictions), set on the pull request's destination branch.
- When every required merge check except successful builds is done, you can select Merge while the build is still running. The merge happens as soon as the build succeeds, and is blocked if it fails.
- It does not wait for approvals or other checks: those have to be done before Merge is offered. Atlassian's documentation describes no API for it.
Auto-merge in IntelliJ IDEA
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pull requests of Bitbucket Cloud and Bitbucket Data Center in an IDE tool window with their merge checks. From version 1.0.38, on Data Center 8.15 and later with auto-merge turned on, its Merge dialog offers auto-merge while checks block the merge, with the strategy and message you choose. The pull request then says auto-merge is on, with a link to cancel it. It is not offered on Cloud. The review inbox and the merge checks are free; approving, commenting and merging are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Bitbucket is a trademark of Atlassian Pty Ltd; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: pull request builds · Bitbucket merge checks · Bitbucket merge strategies · modify a pull request based on out-of-date information (Data Center) · Bitbucket merge queues · Bitbucket pull request plugins for IntelliJ IDEA, compared · 日本語