> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/code-repository/3.0/use-harness-code/pull-requests/delete-branch.md).

# Delete Branch After PR Merge or Close

Harness Code lets you easily delete the source branch of a pull request after it’s merged or closed, helping teams keep their repositories clean and reducing stale branches.

### When the Delete Branch option appears <a href="#when-the-delete-branch-option-appears" id="when-the-delete-branch-option-appears"></a>

After a pull request is **merged** or **closed**, a **Delete Branch** button appears on the PR page if the following conditions are met:

* The source branch has **not already been deleted**.
* The source branch has **not been updated** since the PR was created.
* The branch deletion is **allowed by the branch rule**, or the current user is in the **bypass list** for that rule.

### When the button is not shown <a href="#when-the-button-is-not-shown" id="when-the-button-is-not-shown"></a>

You won't see the **Delete Branch** button if:

* The source branch has already been deleted.
* The source branch has received new commits since the PR was opened (to prevent accidental deletion of ongoing work).
* A branch rule exists that **prevents deletion**, and you are **not listed in the bypass list** for that rule.

### How to delete a branch manually <a href="#how-to-delete-a-branch-manually" id="how-to-delete-a-branch-manually"></a>

If the delete button isn’t available, you can still delete the branch manually from the **Branches** tab of the repository—assuming you have permission and there’s no protection rule preventing it.
