Looking for a Halp replacement?
See how we compare ➜

How to create Bitbucket Pull Requests (Step by Step)

Master Bitbucket pull requests. Learn how to create PRs via Bitbucket interface, REST APIs, or Slack with Actioner. Read now!

Bitbucket pull requests can be created through Bitbucket's interface, using REST APIs, or through Actioner in Slack.

Now let's look at the first way:

Method 1: Bitbucket Interface

Authorization level: You must have at least "Write" permissions on the repository to create a pull request.

Requirements: You need to have a Bitbucket account and be logged in to create a pull request through the web interface and Git installed.

Here's a step-by-step guide to help you create a pull request using Bitbucket:

Step 1: Create a new branch: 

Before creating a pull request, it's a good practice to create a new branch to work on your changes. This keeps the main branch clean and makes it easier to manage the changes.

git checkout -b your-feature-branch

Step 2: Commit your changes: 

Make the necessary changes in your code, then stage and commit them to your new branch.

git add .
git commit -m "Your commit message describing the changes"

Step 3: Push the new branch to the remote repository: 

Push your changes to the remote repository on Bitbucket.

git push origin your-feature-branch

Step 4 - Option 1: Create a pull request via direct link

Now that your branch has been pushed to the remote repository, you can create a pull request via using the link in the “git push” commands response.

Create a pull request via direct link
Create a pull request via direct link
  1. Open the link in your web browser.
  2. Optionally, you can update the title and a description for your pull request. Make sure to provide enough context for the reviewers to understand your changes.
  3. Optionally, you can add reviewers, labels, and tasks to the pull request.
  4. Click on the "Create pull request" button to create the pull request.
Create PR from Bitbucket interface
Create PR from Bitbucket interface

Step 4 - Option 2: Create a pull request

Now that your branch has been pushed to the remote repository, you can create a pull request.

  1. Go to the Bitbucket repository in your web browser.
  2. Click on the "Pull requests" tab in the left sidebar.
  3. Click on the "Create pull request" button. 
  4. On the "Create a pull request" page, select the source branch (your-feature-branch) and the destination branch (usually the main branch or the branch you want to merge your changes into).
  5. Add a title and a description for your pull request. Make sure to provide enough context for the reviewers to understand your changes.
  6. Optionally, you can add reviewers, labels, and tasks to the pull request.
  7. Click on the "Create pull request" button to create the pull request.

Step 5: Address feedback and merge the pull request: 

Once the pull request is created, your teammates can review the changes and provide feedback. Address any comments or issues they raise. When the changes are approved, you or someone with write access to the repository can merge the pull request into the destination branch.

Step 6: Clean up your branch: 

After the pull request is merged, it's a good practice to delete the feature branch, both locally and remotely.

git branch -d your-feature-branch
git push origin --delete your-feature-branch

That's it! You've successfully created and merged a pull request in Bitbucket.

Learn how to delete a Bitbucket PR ➡️

Method 2: REST API

Authorization level: You must have at least "Write" permissions on the repository to create a pull request.

Requirements:

  • You need to have a Bitbucket account.
  • An API access token or an app password with the necessary permissions (e.g., "Repository: Write" and "Pull requests: Write") is required to authenticate your requests to the Bitbucket REST API. You can generate an access token or an app password from your Bitbucket account settings.

You can create a pull request using the Bitbucket REST API.  Here's how to do it:

  1. To create a pull request using the Bitbucket REST API, you'll need to make an HTTP POST request to the following URL:and description:
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests
  1. Replace {workspace} with your workspace ID or username and {repo_slug} with the repository slug (the unique identifier for your repository). You'll need to include a JSON payload in the body of the request, specifying the source branch, destination branch, title, and description:
{
 "title": "Your pull request title",
  "description": "Your pull request description",
  "source": {
    "branch": {
      "name": "your-feature-branch"
    }
  },
  "destination": {
    "branch": {
      "name": "main"
    }
  }
}
  1. Here's a sample curl command to create a pull request: 
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {your_access_token}" -d '{"title": "Your pull request title", "description": "Your pull request description", "source": {"branch": {"name": "your-feature-branch"}}, "destination": {"branch": {"name": "main"}}}' "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests"
  1. Replace {your_access_token} with your Bitbucket API access token, which you can generate in your account settings.

Method 3: Using Actioner in Slack

You can also create PRs in Slack by using Actioner’s Bitbucket integration. Follow the steps below;

  1. Call Actioner in Slack
  2. From the workflows list select List active branches.
  3. Find the branch for which you want to create a PR. 
  4. Form the ellipsis select Create PR workflow. 
  5. Please fill out the required fields, e.g. Reviewers.
  6. Click Create.
CI&CD in Slack

For more information on how to use Bitbucket in Slack check out Bitbucket PR management and Continuous integration & delivery use cases

Feel free to contact us through the Actioner Slack community whenever you need help.

Similar posts

DevOps

GitHub integration: Exploring connection methods with Actioner

Learn to securely connect GitHub via Actioner using OAuth2, classic, or fine-grained personal access tokens. Boost security, control, and flexibility in GitHub workflows.

Canturk Sen
How-to

How to make a Poll in Slack

Quickly create Slack polls with the free Slack poll app. Start making prompt and collaborative decisions with quick and simple polls on Slack.

Aysegul Yavuz Gokcuoglu
DevOps

Building GitHub AI code review assistant with Actioner

Build your own GitHub Al assistant for pull request code reviews. Interact with the Al copilot, request to make changes to the PR according to its suggestions.

Canturk Sen