Automerge#
Atlantis can automatically merge a pull request after every plan in that PR has been successfully applied. The feature is implemented in server/events/automerger.go, which exposes the AutoMerger struct wired to a VCS client.
Enabling Automerge#
Automerge is opt-in and can be enabled at two scopes :
| Scope | Mechanism |
|---|---|
| Server-wide | --automerge flag / ATLANTIS_AUTOMERGE env var on atlantis server |
| Per-repo | automerge: true in the repo's atlantis.yaml |
Per-repo config takes precedence over the server-wide flag . Automerge can be disabled for a single apply command via atlantis apply --auto-merge-disabled .
Requirements before merging:
- All plans in the PR must succeed before any can be applied .
- All plans must be applied before automerge fires .
- The Atlantis VCS user must have merge permissions on the repo .
Merge Method Configuration#
Three merge methods are supported for GitHub: merge, rebase, and squash . A fourth, fast-forward, was introduced for Gitea/Forgejo, Bitbucket Cloud, and Bitbucket Server by PR #6681 .
Configuration follows a three-tier precedence (highest → lowest) :
--auto-merge-methodcomment flag — per-apply override:atlantis apply --auto-merge-method squashautomerge_methodinatlantis.yaml— per-repo default (added in PR #6681)--automerge-methodserver flag /ATLANTIS_AUTOMERGE_METHODenv var — global default (added in PR #6573)
In automerger.go, if the comment command carries no method, the GlobalAutomergeMethod from the server config is used as fallback.
VCS Provider Support Matrix :
| Method | GitHub | GitLab | Gitea/Forgejo | Bitbucket Cloud | Bitbucket Server | Azure DevOps |
|---|---|---|---|---|---|---|
merge | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
rebase | ✓ | — | ✓ | — | ✓ | ✓ |
squash | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
fast-forward | — | — | ✓ | ✓ | ✓ | — |
GitHub MergePull Behavior#
The GitHub VCS MergePull function:
- Fetches the repo to determine which merge methods it allows (
AllowMergeCommit,AllowRebaseMerge,AllowSquashMerge) . - If a
MergeMethodis specified inPullRequestOptions, validates it against the repo's allowed methods and returns a clear error if unsupported . - If no method is specified, auto-selects:
merge→rebase→squashin priority order, skipping any the repo disallows . - Calls
PUT /repos/{owner}/{repo}/pulls/{num}/mergewith an empty commit message (GitHub auto-generates it) .
Error Handling#
When MergePull fails, automerger.go posts a failure comment on the PR with the error message, so the team is notified without requiring log access. Commenting about the automerge attempt itself is non-fatal — failures there are logged and the merge still proceeds .
GitHub Merge Queue Support#
GitHub's merge queue requires merge_group webhook events instead of the standard pull_request webhooks. PR #6435 adds end-to-end support .
How it works:
- Pre-flight detection: A GraphQL query checks
branchProtectionRule.requiresMergeQueue(classic branch protection) and inspects rulesets for an activeMERGE_QUEUErule. If detected, Atlantis usesenablePullRequestAutoMergeGraphQL mutation instead of direct REST merge . - Post-flight fallback: If the REST merge returns
405 Method Not Allowedwith a merge-queue error, Atlantis automatically retries via GraphQL auto-merge. This handles cases where the pre-flight query is incomplete (e.g., >100 ruleset rules) . - Merge group events: When GitHub emits a
merge_groupevent withchecks_requested, Atlantis postssuccessstatuses forplan,apply, andpolicy_checkon the merge group's head SHA — unblocking the queue without re-running Terraform (since the PR was already validated before entering the queue) .
Configuration required:
- Enable the flag:
--gh-merge-queue-enabled/ATLANTIS_GH_MERGE_QUEUE_ENABLED=true. - Subscribe the GitHub webhook (or GitHub App) to the
merge_groupevent . - Grant the Atlantis VCS user/App permission to enable auto-merge on the repository .
Note: Before PR #6435 landed, the incompatibility between Atlantis and GitHub merge queues was a known blocker — Atlantis would ignore
merge_groupwebhooks entirely, leaving PRs stuck .
Key Source Files#
| File | Purpose |
|---|---|
server/events/automerger.go | Core automerge orchestration logic |
server/events/vcs/github/client.go | GitHub MergePull implementation with method selection |
server/events/models/models.go | PullRequestOptions struct (carries MergeMethod, DeleteSourceBranchOnMerge) |
server/user_config.go | Automerge and AutomergeMethod config fields |
server/events/comment_parser.go | --auto-merge-method flag parsing |
server/events/apply_command_runner.go | Invokes automerge() with the parsed method |