Create pull requests

Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018

Visual Studio 2022 | Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015

Create pull requests (PRs) to change, review, and merge code in a Git repository. You can create PRs from branches in the upstream repository or from branches in your fork of the repository. Your team can review the PRs and give feedback on changes. Reviewers can step through the proposed changes, leave comments, and vote to approve or reject the PRs. Depending on branch policies and other requirements, your PR might need to meet various criteria before you can complete the PR and merge the changes into the target branch.

For PR guidelines and management considerations, see About pull requests.

Prerequisites

  • Repos must be enabled on your project. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.

  • To view or review PRs, you must be a member of an Azure DevOps project with Basic access or higher.

  • To contribute to a PR, you must be a member of the Readers security group or have the corresponding permissions.

  • To create and complete a PR, you must be a member of the Contributors security group or have the corresponding permissions.

    Note

    For public projects, users granted Stakeholder access have full access to Azure Repos.

  • Repos must be enabled on your project. If the Repos hub and associated pages don't display, see Turn an Azure DevOps service on or off to reenable Repos.
  • To view or review PRs, you must be a member of the Azure DevOps project with Basic access or higher. If you aren't a project member, get added.
  • To create and complete a PR, you must be a member of the Contributors security group, or have the corresponding permissions, in the project you want to change.
  • To contribute to a PR, you must be a member of the Readers security group or have the corresponding permissions.
  • To create and complete a PR, you must be a member of the Contributors security group or have the corresponding permissions.
  • To view or review PRs, you must be a member of an Azure DevOps project with Basic access or higher. If you aren't a project member, get added.
  • To contribute to a PR, you must be a member of the Readers security group or have the corresponding permissions.

Create a pull request

You can create a new PR from the Azure DevOps project website, from Visual Studio, or from the Azure DevOps CLI.

From the Azure DevOps project website, you can create a new PR from:

Create a PR from the Pull requests page

You can create PRs for any branch from your project's Pull requests page on the web.

  1. On the Repos > Pull requests page, select New pull request at upper right.

    Screenshot of the New pull request button.

  2. Select the branch with the changes and the branch you want to merge the changes into, such as the main branch.

    Screenshot of source and target branches for a P R in Azure Repos.

  3. Enter your PR details and create the PR.

Create a PR from a pushed branch

After you push or update a feature branch, Azure Repos displays a prompt to create a PR.

  • On the Pull requests page:

    Screenshot that shows the prompt to create a P R on the Pull Requests tab in Azure Repos.

  • On the Files page:

    Screenshot that shows the prompt to create a P R on the Files tab in Azure Repos.

Select Create a pull request to go to a page where you can enter your PR details and create the PR.

After you push or update a feature branch, Azure Repos prompts you to create a PR in the Code view on the web. This prompt is displayed on Pull Requests and Files.

Screenshot that shows the prompt to create a P R on the Pull Requests tab in Azure Repos.

Screenshot that shows the prompt to create a P R on the Files tab in Azure Repos.

Select Create a pull request to go to a page where you can enter your PR details and create the PR.

Create a PR from a linked work item

You can create a PR directly from an Azure Boards work item linked to the branch.

  1. In Azure Boards, from Backlogs or Queries in the Work view, open a work item that's linked to the branch.

  2. In the Development area of the work item, select Create a pull request.

    Screenshot of creating a PR from the Development area of a work item with a linked branch.

The link takes you to a page where you can enter your PR details and create the PR.

Add updates with cherry-pick

You can copy commits from one branch to another by using cherry-pick. Unlike a merge or rebase, cherry-pick only brings the changes from the commits you select, instead of all the changes in a branch.

To cherry-pick changes from a completed PR, select Cherry-pick on the PR's Overview page. To copy changes from an active PR, select Cherry-pick from the PR's More options menu. This action creates a new branch with the copied changes. You can then create a new PR from the new branch. For detailed instructions, see Copy changes with cherry-pick.

Switch source and target branches of your pull request

Before the first time you save a PR, you can switch the source and target branches of the PR by selecting the Switch source and target branches icon next to the branch names. Once the PR is active, this icon goes away, but you can still change the target branch of the PR.

Screenshot of the switch source and target branches icon.

Use pull request templates

A pull request template is a file containing Markdown text that populates the PR description when you create a PR. Good PR descriptions tell PR reviewers what to expect, and can help track tasks like adding unit tests and updating documentation. Your team can create a default PR template that adds text to all new PR descriptions in the repo. Also, you can select from branch-specific templates or other templates your team defines. For more information about creating and using PR templates, see Improve pull request descriptions using templates.

If your repo has a default template, all PRs in the repo have the default template's description text at creation. To add other templates, select Add a template and then choose a template from the dropdown list. You can edit the template text in your description, remove it, or add other text.

Screenshot showing Add a template when creating a P R.

Create draft PRs

If your PR isn't ready for review, you can create a draft PR to indicate work in progress. When the PR is ready for review, you can publish it, and begin or resume the full review process.

Draft PRs have the following differences from published PRs:

  • Build validation policies don't run automatically. You can queue build validations manually by selecting the more options menu in the PR.

  • Voting is disabled while in draft mode.

  • Required reviewers aren't automatically added. Notifications are sent only to reviewers that you explicitly add to the draft PR.

  • Draft PRs display in the PR list with a Draft badge.

    Screenshot showing a draft P R in the P R list.

Note

Creating draft PRs requires Azure DevOps Server 2019.1 update or later version.

To create a draft PR, select the arrow next to Create and select Create as draft when creating the PR. You don't have to use title prefixes such as WIP or DO NOT MERGE.

Screenshot showing Create as draft P R.

When you're ready to have the PR reviewed and completed, select Publish at upper right in the PR. Publishing a PR assigns required reviewers, evaluates policies, and kicks off voting.

Screenshot showing Publish for a P R.

To change an existing published PR to a draft, choose Mark as draft. Marking a PR as draft removes all existing votes.

Screenshot showing Mark as draft.

Note

This feature requires Azure DevOps Server 2019.1 update or later version.

Add or edit pull request title and description

On the New pull request page, enter a Title and detailed Description of your changes, so others can see what problems the changes solve. On a new PR as in existing PRs, you can see the Files and Commits in your PR on separate tabs. You can add reviewers, link work items, and add tags to the PR.

When you're ready to have your changes reviewed, select Create to create the PR.

Screenshot that shows creating a new P R.

Adding details to a new P R.

Don't worry if you don't have all of the work items, reviewers, or details ready when you create your PR. You can add or update these items after you create the PR.

Edit PR title and description

Keep the PR title and description up to date so reviewers can understand the changes in the PR.

You can update the title of an existing PR by selecting the current title and updating the text. Select the Save icon to save changes, or select the Undo icon to discard the changes.

Edit the PR description by selecting the Edit icon in the Description section.

Screenshot that shows editing the P R title and selecting the description Edit button.

Add reviewers to a pull request

You can add reviewers in the Reviewers section of a new or existing PR. You can also make existing optional reviewers required, or change required reviewers to optional or remove them, unless they're required by policy.

Branch policies can require a minimum number of reviewers, or automatically include certain optional or required reviewers in PRs. You can't remove reviewers that are required by branch policy. You can change branch policy optional reviewers to be required, or remove them.

To see the branch policy that automatically added a reviewer, in the Reviewers section of the PR Overview page, right-click More options next to the reviewer.

Screenshot that shows View policy on a reviewer that's automatically included by branch policy.

If the user or group you want to review your PR isn't a member of your project, you need to add them to the project before you can add them as reviewers.

To add reviewers to a new PR:

  1. On the New pull request page, under Reviewers, select Search users and groups to add as reviewers.
  2. As you enter a name or email address, a dropdown list shows a list of matching users and groups. Select names from the list to add as optional reviewers.
  3. To add required reviewers, select Add required reviewers, and then select Search to add required reviewers to search for and select the names.

Screenshot of adding a reviewer to a new P R.

To add reviewers to an existing PR:

  1. In the Reviewers section of the Overview page, select Add, and then select Required reviewer or Optional reviewer.

    Pull request overview

  2. As you enter a name or email address, a list of matching users or groups appears. Select the names to add as reviewers.

    Add P R reviewer.

To change a reviewer between required and optional, or remove a reviewer, select More options to the right of the reviewer name. To see the membership of a group or team designated as a reviewer, select the group's icon.

To add reviewers to your PR:

  1. Select the Overview tab in the PR.

    PR overview

  2. Select the add button in the Reviewers area.

  3. Enter the name of the user or group to add to the reviewer list for the PR. If the user isn't a member of your project, you'll need to add them.

  4. As you enter a name or email address, a list of matching users or groups appears. Select the user or group from the list to add them as a reviewer.

    Add PR reviewer

To link work items to a new PR:

  1. On the New pull request page, under Work items to link, select Search work items by ID or title.
  2. Start to enter a work item ID or title, and select the work item to link from the dropdown list that appears.

To link work items to an existing PR:

  1. On the PR Overview tab, in the Work items area, select +.

    Screenshot that shows selecting the Overview tab and the work items section.

  2. Enter the ID of the work item or search for the work item title. Select the work item from the list that appears.

Remove a work item link by selecting the x icon next to the work item. Removing a link only removes the link between the work item and the PR. Links created in the branch or from commits remain in the work item.

To link work items to your PR:

  1. Select the Overview tab in the PR.

    Screenshot that shows selecting the Overview tab and the link items button.

  2. Select the add button in the Work Items area. Add icon in PRs

  3. Enter the ID of the work item or search for work items with titles that match your text. Select the work item from the list that appears.

Remove work item links by selecting the remove button that appears when you hover over the work item. remove button Removing a link only removes the link between a work item to a PR. Links created in the branch or from commits stay in the work item.

To link work items to your PR:

  1. Select Overview in the PR.

    Select Overview in the PR.

  2. Select the add button in the Work Items area.

  3. Enter the ID of the work item or search for work items with titles that match your text. Select the work item from the list that appears.

Remove work item links by selecting the remove button that appears when you hover over the work item. remove icon Removing a link only removes the link between the work item and the PR. Links created in the branch or from commits stay in the work item.

Add tags to a pull request

Use tags to show important details and help organize PRs. Tags can communicate extra information to reviewers, such as that the PR is still a work in progress, or is a hotfix for an upcoming release.

Screenshot showing P Rs with tags.

To add a tag when creating a PR, type a tag name in the Tags section. After you create the PR, you can manage tags in the Tags section.

Screenshot that shows the P R Tags section highlighted.

Add labels to a pull request

You can communicate extra information about a PR to the reviewers by using labels. Maybe the PR is still a work in progress, or it's a hotfix for an upcoming release. Use labels to communicate important details and help organize PRs.

Note

Using PR labels requires TFS 2018.2 or later version.

Screenshot showing P Rs with labels.

To add a label when creating a PR, choose Add label. After you create a PR, you can manage its labels in the Labels section.

Add P R label

Add attachments to pull requests

You can attach files, including images, to your PR during or after creation. Select the paper clip icon below the Description field, or drag and drop files directly into the Description field of the PR.

Screenshot that shows attaching files to the P R description during creation.

Change the target branch of an active pull request

For most teams, nearly all PRs target a default branch, such as main or develop. If you sometimes need to target a different branch, it's easy to forget to change the target branch when you create the PR. If that happens, you can change the target branch of an active PR:

  1. Select More actions at upper-right on the PR Overview page, and then select Change target branch from the dropdown menu.
  2. In the Change target branch pane, select Choose a target branch, select the new branch, and then select Change.

Email pull request notifications to stakeholders

You can share a pull request by email to notify reviewers and communicate with team members. To share a PR:

  1. Select More options on the PR Overview page, and then select Share pull request.

    Screenshot that shows selecting Share pull request on a P R's Overview page.

  2. On the Share pull request screen, add recipients by typing their names in the To: field and selecting from the user names that appear. You can also remove recipients.

  3. Add an optional message in the Note (Optional) field, and then select Send. Recipients receive an email requesting their attention and linking to the PR.

Note

If you use the built-in email feature, you can only send the email to project members' individual addresses. Adding a team group or security group to the To: line isn't supported. If you add an email account that the system doesn't recognize, you receive a message that one or more recipients of your email don't have permissions to read the mailed pull request.

For the email feature to work, your administrator for Azure DevOps Server must configure an SMTP server.

Next steps