Skip to content

gh merge pr -s -d does not delete PR branch if on a fork different from base branch #2860

Description

@VRanga000

Describe the bug

 ❯ gh --version
gh version 1.5.0 (2021-01-21)
https://github.com/cli/cli/releases/tag/v1.5.0

When merging a PR from a branch on a different fork (than the base branch) with squash and delete enabled via the gh cli causes the PR to be merged with a squashed commit, but the source branch is not deleted either locally or remotely.

Steps to reproduce the behavior

  1. Create a PR from a branch on a fork different from the base branch.
  2. Merge the PR via the cli with squash and delete-branch enabled: gh merge pr -s -d xx
  3. The PR should get merged and the source branch deleted locally and remotely.

Expected vs actual behavior

Expected result:
The PR should get merged and the source branch deleted locally and remotely.

Actual result:
The PR gets merged but the source branch are not deleted locally or remotely.

Logs

 ❯ gh pr merge -s -d 50
✔ Squashed and merged pull request #50 (Various updates)
 ❯ gbd feature/updates                                                                                                                 
warning: deleting branch 'feature/updates' that has been merged to
         'refs/remotes/origin/feature/updates', but not yet merged to HEAD.
Deleted branch feature/updates (was 0d02dc6).
 ❯ gp origin :feature/updates                                                                                                          To github.comcast.com:VRanga000/pulumi.git
 - [deleted]         feature/updates

Activity

  1. mislav commented on Jan 27, 2021

    @mislav
    Contributor

    Thank you for reporting!

    We currently avoid trying to delete a branch if the PR is cross-repo because an OSS maintainer who is merging cross-repo PRs typically doesn't have permissions to delete the branch in a fork that they don't own. However, we could also try to detect branch permissions and allow you to delete your branch even for PRs that are cross-repo. 👍

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    on Jan 27, 2021
  3. added
    gh-prrelating to the gh pr command
    on Oct 2, 2023
  4. TyceHerrman commented on Aug 10, 2026

    @TyceHerrman

    Related GitHub product-feedback discussion: community#201691

    requests an opt-in way to automatically delete a source branch in a contributor's fork after its pull request is merged into the upstream repository

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-prrelating to the gh pr commandpriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions