Skip to content

Query on availability of Delete Branch tool #1476

Open

Description

@klakshmikantha

Hi,

In the set of tools listed, I can see 'create branch' and 'delete file' tools but not 'delete branch'. Is this intentionally excluded?
Is it in the roadmap to add the tool with some guardrails like only allow deleting unprotected branches or branches created by the MCP server tool?
Appreciate any inputs.

Thank you.

Activity

  1. bfedorov-clgx commented on Apr 23, 2026

    @bfedorov-clgx

    hello team!

    I agree with colleague, it's highy necessary feature. Please add delete_branch tool.

  2. nmime commented on Jun 1, 2026

    @nmime

    Can it be added?

  3. huzaifa678 commented on Jun 28, 2026

    @huzaifa678

    Hello I'd like to pick this up. I've implemented a delete_branch tool following the same pattern as the existing create_branch, with the guardrail suggested above: it fetches the branch first and refuses to delete protected branches, returning a clear error to the model instead of attempting the deletion.

    The Behavior:

    Required params: owner, repo, branch
    Checks branch protection via GET /repos/{owner}/{repo}/branches/{branch} before deleting
    Deletes via DELETE /repos/{owner}/{repo}/git/refs/heads/{branch}
    ReadOnlyHint: false, scoped to repo
    Tests cover success, protected-branch refusal, branch-not-found, and delete-failure cases. Happy to adjust the guardrail scope (e.g. also blocking the default branch) based on maintainer preference. Opening a PR shortly.

  4. illichso commented on Nov 16, 2026

    @illichso

    +1 for a delete_branch tool in the repos toolset.

    My agents push short-lived work branches and ship the work to main.
    After that the branch is stale, and the agent cannot remove it.
    Today a person has to delete each one on the Branches page.

    A delete_branch tool could call DELETE /repos/{owner}/{repo}/git/refs/heads/{branch}.
    It should refuse the default branch and respect rulesets and branch protection.

    Is this planned?

  5. huzaifa678 commented on Nov 16, 2026

    @huzaifa678

    Yes this is implemented in #2790 (targeting main), which closes this issue.

    On the guardrails you raised:

    • Branch protection: before deleting, the tool calls GET /repos/{owner}/{repo}/branches/{branch} and refuses with a clear error if the branch is protected, so it won't delete a classic-protected branch.
    • Rulesets: the pre-check only reads the classic protected flag. If a ruleset blocks the deletion, the DELETE call itself fails and the tool surfaces that API error to the model instead of reporting success — so a ruleset-protected branch is still safe, just caught at the delete step rather than the pre-check.
    • Default branch: not special-cased yet. It's normally protected (so usually caught above), but I'm happy to add an explicit default-branch refusal if maintainers want a belt-and-suspenders guard.

    Tests cover success, protected-branch refusal, branch-not-found, and delete-failure, and pass locally. The branch has the latest main merged in to clear the earlier conflicts; CI is still running on the new head.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions