Important Notice: Actioner service has been discontinued. Current customers may contact us for assistance. We appreciate your support and understanding!

How to delete a Bitbucket Pull Request (Step-by-step instructions)

Discover how to decline a Bitbucket pull request. We've provided detailed guidance for each approach through a series of clear steps. Check them all now!

A pull request is a feature in Bitbucket that allows developers to propose changes to a codebase. However, sometimes a pull request may no longer be needed or may have been submitted in error. In such cases, you may want to delete the pull request. 

We have listed three ways to delete a Bitbucket pull request and explain each method's authorization levels and requirements:

Let's find out which method works best for you.

Method 1: Using Bitbucket web interface

The first and easiest way to delete a pull request in Bitbucket is to use the web interface. Here are the steps involved:

1. Log in to Bitbucket and navigate to the repository that contains the pull request you want to delete.

Repos-in-bitbucket

2. Click on the "Pull Requests" tab to see a list of all the open pull requests for the repository.

Pull-Requests-tab-in-bitbucket

3. Find the pull request you want to delete and click on it to open it.

4. Once the pull request is open, you should see a button on the top right-hand side that says "Decline." Click on this button.

Delete-pull-Request-in-bitbucket

5. A confirmation window will appear, asking you to confirm that you want to decline the pull request. Click on "Decline pull request" to confirm.

Confirm-deleting-Pull-Request-in-bitbucket

6. The pull request will be deleted.  You won't see it in your list of pull requests anymore.

It is necessary for you to have at least "write" access to the repository to use this method. This means that you must be a member of a group or have been given explicit permission to modify the repository by the repository owner or an administrator.

Learn how to create a Bitbucket PR ➡️

Method 2: Using Bitbucket API

The Bitbucket API allows developers to interact with Bitbucket programmatically. This method can be useful if you need to automate the process of deleting pull requests. Here are the steps involved:

  1. First, you will need to generate a personal access token with the "Pull Requests: Write" permission. Go to your account settings to do this, clicking on "Access Management," and then clicking on "Personal access tokens."
  2. Create a new personal access token with the "Pull Requests: Write" permission.
  3. Copy the access token to your clipboard, as you will need it in the next step.
  4. Open a command prompt or terminal window and use the following command to delete the pull request:
curl -X DELETE -H "Authorization: Bearer <your_access_token>" https://api.bitbucket.org/2.0/repositories/<workspace>/<repo_slug>/pullrequests/<pull_request_id>

Replace <your_access_token> with the access token you generated in step 2, <workspace> with the name of your Bitbucket workspace, <repo_slug> with the slug of the repository where the pull request is located, and <pull_request_id> with the ID of the pull request you want to delete. You can find the ID of the pull request in the URL of the pull request page.

  1. Press enter to run the command. The pull request will be deleted, and you should see a JSON response indicating the operation was successful.

To use this method, you must have a personal access token that has the "Pull Requests: Write" permission.

Method 3: Using Git

The third method to delete a pull request in Bitbucket is by using Git. Here are the steps involved:

  1. Open a command prompt or terminal window and navigate to the local repository that corresponds to the pull request you want to delete.
  2. Use the following command to list all the branches in your repository:
git branch -a
  1. Find the branch associated with the pull request that you want to delete. Note down the name of this branch.
  2. Use the command below to delete the branch associated with the pull request. Replace <branch_name> with the name of the branch that you noted down in step 3. This command will delete the branch and, as a result, the associated pull request.
git push origin --delete <branch_name>
  1. Once the branch is deleted, the pull request will no longer be visible in Bitbucket.

To use this method, you must have “write” access to the repository and the ability to push changes to the remote repository. This means that you must be a member of a group or have been given explicit permission to modify the repository by the repository owner or an administrator.

Using Slack and Bitbucket?

Explore our Bitbucket pipelines and PR management apps for Slack

  • Run Bitbucket pipelines in Slack
  • Track pipeline status
  • Automatically create Pull request channels
  • Stay updated on check statuses, PR reviews, comments, and more within Slack.

Similar posts

DevOps

Top 10 CI CD Tools for 2024: Pros and Cons

Explore top CI/CD tools for 2024! This blog provides insights on GitHub Actions, GitLab CI/CD, and more, helping DevOps pros optimize software development.

Kadir Turker Gulsoy
DevOps

Perfect DevOps Trio: Slack, GitHub and Actioner

Revolutionize your workflow with Actioner's GitHub Actions Workflows app for Slack. Trigger, monitor, and manage GitHub workflows directly in Slack, enhancing productivity and collaboration.

Kadir Turker Gulsoy
DevOps
News

Running ​​GitLab CI/CD pipelines in Slack made easy

Effortlessly run GitLab CI/CD pipelines in Slack with Actioner. No coding needed—initiate, monitor, and get real-time updates. Install the GitLab CI/CD app now!

Canturk Sen