Create a pull request in Visual Studio
If you’re authenticated to GitHub or Azure DevOps and have pushed changes to your remote repository, you can create a pull request without leaving Visual Studio. Pull requests are an essential tool in GitHub and Azure DevOps for code review. These reviews help catch issues in new features and allow teammates to share their experience with different regions of the codebase – improving the health of the codebase overall.
Note
To try out the feature, ensure it’s enabled in Tools > Options > Preview Features > Pull Request
To create a pull request, follow these steps:
Before you can create a pull request, you need to create a new branch for your changes. This branch keeps your modifications separate from the main branch until they’re ready to be merged.
Then, you can commit and push your changes as you normally would in the Git Changes window.
Select the link in the notification banner to Create in Visual Studio or Create in Browser.
Alternatively, you can create a pull request from a remote branch by navigating to the New Pull Request window via the top-level menu Git > GitHub or Azure DevOps > New Pull Request. Or right-click a branch in the Git Repository Window.
Or right select a branch in the Git Repository Window to open the context menu and select New Pull Request.
Select the branch that you want to merge into and give your pull request a descriptive title and description. You can use markdown syntax to format your pull request description from Visual Studio. Try it out by typing the markdown symbols in the Description box and preview your markdown by selecting the Preview button.
Tip
With Visual Studio 2022 version 17.10 preview 2 and later and the GitHub Copilot extensions, you can use AI to generate a detailed pull request description that describes your changes. Press the sparkle pen icon to request that GitHub Copilot generate a PR description. To install GitHub Copilot, see Install and manage GitHub Copilot in Visual Studio.
The difference preview allows you to see all the changes in the files that have been committed as a part of your pull request. See Compare files - diff view.
Tip
The summary difference view option allows you to review only the changed sections of code.
You can link work items by referencing them with the issue search, by typing
#
in the description box or pressing the # button in the lower right corner. You can also add your reviewers by typing their GitHub username or Azure DevOps identity or email.Once you’ve clicked Create on your pull request, other developers can review your changes and provide feedback. Or, with Visual Studio 17.12 and later, click the dropdown and choose Create as draft.
With Visual Studio 17.12 and later, you can enable the Pull Request Templates feature (in Tools > Options > Environment > Preview Features) so that your default PR template in your repo will be used when creating a new pull request for both GitHub and Azure DevOps. Learn more about how to add a pull request template to your repository in the GitHub documentation and Azure DevOps documentation.
View pull request comments in the editor
As of Visual Studio 17.11, you can view comments and suggestions from reviewers without switching contexts to the browser.
To enable this feature, open Tools > Options > Preview features and make sure that Pull Request Comments is selected.
To view the comments for a pull request, check out any branch with an active pull request branch and select Show comments in files from the infobar. You can also select the PR number in the Git Changes window or from the Git top level menu with Git > GitHub or Azure DevOps > Show comments in files.
You can navigate across files and individual comments using the icons in the toolbar, or use the following keyboard shortcuts:
Action | Keyboard shortcut |
---|---|
Go to the previous file in the pull request | Ctrl+Shift+Alt+F6 |
Go to the next file in the pull request | Ctrl+Alt+F6 |
Go to the previous comment | Ctrl+Shift+Alt+F8 |
Go to the next comment | Ctrl+Alt+F8 |
Next steps
To continue your journey, visit the Fetch, pull, and sync in Visual Studio page.