Skip to content

Want to always have local branch deleted on auto #8801

Description

@xenoterracide

Describe the feature or problem you’d like to solve

I want a single uninteractive command to delete the local branch when the PR is merged

This, almost works, but has a couple of race conditions

gh pr create --fill-first; sleep 3 && gh run watch --exit-status && gh pr merge --squash --delete-branch --auto
  1. The runs might not be available, so we're sleeping first
  2. If we watch the wrong run the local branch won't be deleted if there are still runs

Proposed solution

Let's start with I think there are multiple solutions to this, so I'm doing my best to describe the problem more than just the solution

  1. I think that there needs to be a gh pr watch --exit-status so that we can watch all the runs related to this pr at once.
  2. When running gh pr merge --squash --delete-branch --auto if the merge hasn't been done yet, record some kind of local file queue check, so that the next time gh is run, it'll check and delete the branch if that pr is closed.
  3. We also need a gh pr watch <job name> and maybe a gh run watch --latest --job-name <job name>
❯ gh --version
gh version 2.44.1 (2024-02-29)
https://github.com/cli/cli/releases/tag/v2.44.1

Activity

  1. cli-triage commented on Jul 9, 2026

    @cli-triage

    This is a well-formed enhancement request covering two related capabilities: a gh pr watch --exit-status command for tracking all CI runs tied to a PR, and reliable local branch cleanup after gh pr merge --auto --delete-branch eventually completes. The enhancement label already applied is correct; no new labels from the triage allowlist are needed. No exact duplicates were found — #9073 tracks a related but distinct bug (remote branch not deleted after auto-merge), and #8514 covers --auto not respecting branch-protection check gates. A maintainer may wish to add the gh-pr command label to help with routing.

    Generated by Issue Triage (skills-driven) · 33.6 AIC · ⌖ 6.24 AIC · ⊞ 5K · ◷

  2. BagToad commented on Jul 9, 2026

    @BagToad
    Member

    Going to close out this old issue as a matter of housekeeping and a couple thoughts:

    • gh pr checks --watch exists, so maybe that helps
    • We don't have a strong desire at this time to have a built-in "wait and poll for the PR to merge and then delete the local branch" feature.

    If this is still a feature you'd like to see, I'd encourage opening a fresh issue with new context 🙏

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

    enhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions