> 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/use-harness-code/pull-requests/delete-branch.md).

# Delete Branch After PR Merge or Close

Delete source branches after pull requests are merged or closed in Harness Code.

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.

<figure><img src="https://942965363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoTP6ysjQCQlt5GlFHRfs%2Fuploads%2Fgit-blob-2f9eb0c7c5c46b4abfc6460260858f29fd642219%2Fdelete-branch-post-merge.png?alt=media" alt=""><figcaption></figcaption></figure>

### 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.

{% @harness-feedback/feedback module="code-repository" pagePath="code-repository/use-harness-code/pull-requests/delete-branch" %}
