zaro

How do I Delete a Draft PR?

Published in GitHub Management 4 mins read

Deleting a draft pull request (PR) on GitHub primarily involves removing the Git branch associated with it. When the underlying branch is deleted, the draft PR — just like any other pull request — is automatically closed and removed from your repository's active list.

Step-by-Step Guide to Deleting a Draft PR

To completely remove a draft pull request from your GitHub repository, follow these straightforward steps:

  1. Navigate to Your Repository's Pull Requests:

    • Open your project repository on GitHub.com.
    • Click on the "Pull requests" tab usually found in the top navigation bar of your repository. This will display a list of all active, closed, and draft pull requests.
  2. Locate and Open the Draft Pull Request:

    • From the list of pull requests, identify the specific draft PR you wish to delete. Draft PRs are typically marked with a "Draft" label.
    • Click on the title of the draft pull request to open its detailed view. This action takes you to the PR's dedicated page, where you can see its conversation, commits, checks, and files changed.
  3. Close the Draft Pull Request (Optional but Recommended for Clarity):

    • While not strictly necessary for deleting the branch, closing the draft PR first can make the "Delete branch" button more visible on the PR page.
    • On the draft PR's page, scroll down and click the "Close pull request" button. This will change the PR's status from "Draft" or "Open" to "Closed."
  4. Delete the Associated Branch:

    • Once the pull request is closed (or even if it's still open, but the branch deletion is more direct), a "Delete branch" button will typically appear on the pull request page.
    • Click the "Delete branch" button. Confirm the deletion if prompted. This action permanently removes the branch that the draft PR was based on.

What happens next? Deleting the branch automatically closes and removes the associated pull request from your active pull request list, effectively deleting the draft PR completely.

Understanding Draft PRs and Branch Deletion

A draft pull request serves as a preliminary way to share work and get early feedback without signaling that the code is ready for review or merging. However, like any other PR, a draft PR is intrinsically linked to a specific branch in your repository.

Why Delete the Branch?

  • Direct Removal: Deleting the branch directly removes the code changes and the history associated with that specific PR.
  • Automatic Closure: When the branch a PR is based on is deleted, GitHub automatically closes the corresponding pull request, regardless of whether it's a draft, open, or closed PR. This ensures consistency and tidies up your repository.
  • Repository Cleanliness: It helps keep your repository clean by removing unused or outdated branches and their associated PRs.

Important Considerations Before Deleting

Before proceeding with the deletion of a draft PR, consider the following:

  • Irreversibility: Deleting a branch is a permanent action on GitHub. While you might be able to restore a recently deleted branch within a short window, it's generally best to assume it's irreversible.
  • Loss of Progress: Any unmerged changes within that branch will be lost if not backed up or merged elsewhere.
  • Impact on Collaborators: If others were working on or referencing this specific branch or draft PR, inform them of its deletion to avoid confusion or lost work.

Alternative Method: Deleting the Branch Directly

You can also delete the branch associated with the draft PR directly from your repository's branch list. This achieves the same outcome:

  1. Go to your repository on GitHub.
  2. Click on the "Code" tab, and then click on the "< > branches" link (or "branches" in the left sidebar).
  3. Locate the branch name that corresponds to your draft PR.
  4. Click the red trash can icon (🗑️) next to the branch name to delete it.

Result: Deleting the branch from this page will also automatically close and remove the associated draft pull request from your pull requests list.

Summary of Actions

Action to Take Location Effect on Draft PR
Open Draft PR Pull requests tab > Click PR title View PR details
Close Draft PR (optional) Within open PR page Changes PR status to "Closed"
Click "Delete branch" button Within open/closed PR page Removes branch, deletes PR
Delete branch directly (Alt.) Code tab > Branches > Trash can icon Removes branch, deletes PR

For more information on managing branches and pull requests, refer to GitHub's official documentation: