Skip to content

Support pr auto-merge from gh #2619

Closed

Description

@billygriffin

Describe the feature or problem you’d like to solve

GitHub recently announced PR auto-merge to automatically merge PRs when all checks are passing and the PR is approved with no conflicts.

Proposed solution

We can support this in GitHub CLI. Here's the proposed design:

gh pr merge --auto to enable automerge on a PR.
gh pr merge --auto-disable to disable automerge on a PR.

Additional context

This feature won't be GA until sometime in the next couple months, so we should wait until it's broadly available to ship this in GitHub CLI.

Activity

  1. added
    enhancement
    on Dec 14, 2020
  2. added
    core
    on Dec 14, 2020
  3. self-assigned this
    on Jan 26, 2021
  4. tonytonyjan commented on Feb 7, 2021

    @tonytonyjan

    Really need this on gh pr create and gh pr merge.

  5. AraHaan commented on Feb 7, 2021

    @AraHaan

    I would actually like a setting on the project to where we can enable automerge always from select users (like dependabot where github would merge it for me)

    Currently I had to make an automerge workflow in github actions to do that when all of the checks pass.

  6. amansilla commented on Nov 22, 2021

    @amansilla

    I think the auto option is still missing on gh pr create command. Is this supposed to be implemented?

  7. mislav commented on Nov 23, 2021

    @mislav
    Contributor

    @amansilla No, we've opted to not add the --auto flag to gh pr create. You may separately enable auto-merge for your new PR with the gh pr merge --auto command after running gh pr create.

  8. amansilla commented on Nov 23, 2021

    @amansilla

    All right @mislav! Thanks for the clarification.

  9. AraHaan commented on Nov 23, 2021

    @AraHaan

    @amansilla No, we've opted to not add the --auto flag to gh pr create. You may separately enable auto-merge for your new PR with the gh pr merge --auto command after running gh pr create.

    does that support telling it how it must merge it (like rebase merge for example) too?

  10. mislav commented on Nov 23, 2021

    @mislav
    Contributor

    @AraHaan Yes; please refer to gh pr merge documentation.

  11. CMCDragonkai commented on May 23, 2022

    @CMCDragonkai

    When I run gh pr merge --auto, it still prompts me for how it should merge. Do I need to always use gh pr merge --auto --merge? I'm using this in a CICD.

  12. mislav commented on May 23, 2022

    @mislav
    Contributor

    @CMCDragonkai Yes, you have to explicitly declare a merge strategy.

  13. AraHaan commented on May 23, 2022

    @AraHaan

    boo, it's not like git where we can configure gh config pr.mergeStrategy commit/squash/rebase (which I think would be much better to do to define a default for when one does not explicitly declare it (to use the one from config in that case).

  14. mislav commented on May 24, 2022

    @mislav
    Contributor

    it's not like git where we can configure gh config pr.mergeStrategy

    Does git have a configuration option for a default merge strategy? Would you mind pointing it out to me? I can't see it in git help—the option pr.mergeStrategy does not exist, which makes sense because git has no concept of "Pull Requests".

    We might add a config option in the future, but we will first have to also enable repository-specific config for gh, which we don't have right now. Otherwise, a locally configured default merge strategy will work for some repos but not for others, since GitHub repos can prohibit certain merge strategies in their settings.

    In the meantime, feel free to create a gh alias with your favorite merge strategy:

    gh alias set sq "pr merge --squash"
    
  15. ilian commented on Sep 8, 2022

    @ilian

    @amansilla No, we've opted to not add the --auto flag to gh pr create. You may separately enable auto-merge for your new PR with the gh pr merge --auto command after running gh pr create.

    Please reconsider this decision. Running gh pr merge --auto immedately after gh pr create sometimes results in the following error:

    no pull requests found for branch "test-branch"
    

    I can avoid detecting the PR number from the branch name by capturing the created PR URL returned by gh pr create and providing it as an argument to gh pr merge:

    pr_url="$(gh pr create --fill)"
    gh pr merge --auto -r "$pr_url"
    

    This is also not reliable, as this sometimes fails with the following error:

    GraphQL: Could not resolve to a PullRequest with the number of 183. (repository.pullRequest)
    

    I suspect that the API used by gh pr create returns before the newly created PR is propagated to the entire system. The second command might interact with an API endpoint that does not yet know about the existence of the newly created PR.
    I currently have to resort to a wait and retry mechanism in our CI/CD pipeline as a workaround, but it would be great if this is resolved on the API or CLI side.

  16. blchilders commented on Sep 21, 2022

    @blchilders

    To add to this, when a branch has protections requiring a review the gh pr merge command fails out with:
    Message: At least 1 approving review is required by reviewers with write access., Locations: [{Line:1 Column:58}]

    If the gh create had the option, this error would not be thrown because it would not try to merge until the review came in.

    Is there another work around? Will we just need to create another workflow to trigger when a review happens?

  17. iway1 commented on Jun 26, 2025

    @iway1

    No, we've opted to not add the --auto flag to gh pr create. You may separately enable auto-merge for your new PR with the gh pr merge --auto command after running gh pr create.

    Why? just let people enable it with one command IMO. Why say no to making your CLI more convenient for your users?

  18. BagToad commented on Jun 26, 2025

    @BagToad
    Member

    No, we've opted to not add the --auto flag to gh pr create. You may separately enable auto-merge for your new PR with the gh pr merge --auto command after running gh pr create.

    Why? just let people enable it with one command IMO. Why say no to making your CLI more convenient for your users?

    Hi @iway1 this issue is pretty old and I don't see any of the current maintainers' names in this thread. None of the maintainers in this thread are GitHub staff anymore, so I suspect I'm not alone saying I don't have the full context behind the decision at a glance.

    I recommend opening a new issue that links back to this one, including your use cases and reasoning in that new issue, if you feel we should re-evaluate this previous decision. That'll get fresh eyes on it 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions