Skip to content

Commit d0ced50

Browse files
hubwriterCopilotCopilot
authored
Add documentation for /pr slash command in Copilot CLI (#60826)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 9d0bf03 commit d0ced50

3 files changed

Lines changed: 215 additions & 1 deletion

File tree

content/copilot/how-tos/copilot-cli/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ children:
2525
- /use-copilot-cli-agents
2626
- /administer-copilot-cli-for-your-enterprise
2727
- /speed-up-task-completion
28+
- /manage-pull-requests
2829
- /roll-back-changes
2930
- /chronicle
3031
- /content/copilot/concepts/agents/copilot-cli/about-copilot-cli
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: 'Managing pull requests with the /pr command'
3+
shortTitle: Manage pull requests
4+
intro: 'Use the `/pr` slash command to view, create, and fix pull requests directly from {% data variables.copilot.copilot_cli_short %}.'
5+
versions:
6+
feature: copilot
7+
contentType: how-tos
8+
category:
9+
- Author and optimize with Copilot # Copilot discovery page
10+
- Build with Copilot CLI # Copilot CLI bespoke page
11+
docsTeamMetrics:
12+
- copilot-cli
13+
---
14+
15+
## Overview
16+
17+
The `/pr` slash command lets you manage the full pull request lifecycle without leaving your terminal. You can check pull request status, create new pull requests, and fix common issues such as review feedback, merge conflicts, and CI failures.
18+
19+
## Prerequisite
20+
21+
You must be working in a Git repository that is hosted on {% data variables.product.prodname_dotcom %}.
22+
23+
## Subcommands
24+
25+
The `/pr` slash command has several subcommands that you can use to perform different actions on your pull requests.
26+
27+
> [!NOTE]
28+
> All `/pr` subcommands relate to the current branch—for example, fixing failing CI checks for the pull request associated with the current branch.
29+
30+
<!-- Use HTML tags rather than Markdown to avoid bad column width rendering. -->
31+
32+
<table>
33+
<thead>
34+
<tr>
35+
<th style="width: 20%;">Use this subcommand</th>
36+
<th style="width: 50%;">To do this</th>
37+
<th style="width: 15%; text-align: center;">Requires an existing PR</th>
38+
<th style="width: 15%; text-align: center;">May commit and push</th>
39+
</tr>
40+
</thead>
41+
<tbody>
42+
<tr>
43+
<td><code>/pr</code> or <code>/pr view</code></td>
44+
<td>Show the status of the pull request for the current branch. <a href="#viewing-pull-request-status">Find out more</a></td>
45+
<td align="center">Yes</td>
46+
<td align="center">No</td>
47+
</tr>
48+
<tr>
49+
<td><code>/pr view web</code></td>
50+
<td>Open the pull request in your browser. <a href="#opening-the-pull-request-in-your-browser">Find out more</a></td>
51+
<td align="center">Yes</td>
52+
<td align="center">No</td>
53+
</tr>
54+
<tr>
55+
<td><code>/pr create</code></td>
56+
<td>Create or update a pull request. <a href="#creating-a-pull-request">Find out more</a></td>
57+
<td align="center">No</td>
58+
<td align="center">Yes</td>
59+
</tr>
60+
<tr>
61+
<td><code>/pr fix feedback</code></td>
62+
<td>Address review comments on the pull request. <a href="#fixing-review-feedback">Find out more</a></td>
63+
<td align="center">Yes</td>
64+
<td align="center">Yes</td>
65+
</tr>
66+
<tr>
67+
<td><code>/pr fix conflicts</code></td>
68+
<td>Sync the branch with the base branch and resolve conflicts. <a href="#resolving-merge-conflicts">Find out more</a></td>
69+
<td align="center">Yes</td>
70+
<td align="center">Yes</td>
71+
</tr>
72+
<tr>
73+
<td><code>/pr fix ci</code></td>
74+
<td>Diagnose and fix failing CI checks. <a href="#fixing-ci-failures">Find out more</a></td>
75+
<td align="center">Yes</td>
76+
<td align="center">Yes</td>
77+
</tr>
78+
<tr>
79+
<td><code>/pr fix</code> or <code>/pr fix all</code></td>
80+
<td>Run all three fix phases in order: feedback, conflicts, then CI. <a href="#fixing-all-issues-at-once">Find out more</a></td>
81+
<td align="center">Yes</td>
82+
<td align="center">Yes</td>
83+
</tr>
84+
<tr>
85+
<td><code>/pr auto</code></td>
86+
<td>Create a pull request if needed, then loop through all fix phases until all pull request checks are passing. <a href="#automating-the-full-pull-request-workflow">Find out more</a></td>
87+
<td align="center">No</td>
88+
<td align="center">Yes</td>
89+
</tr>
90+
</tbody>
91+
</table>
92+
93+
Subcommands that commit and push changes will prompt you for permission before performing potentially destructive actions, unless you have pre-allowed those tools. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/allowing-tools).
94+
95+
## Viewing pull request status
96+
97+
To check the status of the pull request associated with your current branch, enter the following in an interactive session:
98+
99+
```copilot copy
100+
/pr
101+
```
102+
103+
### Opening the pull request in your browser
104+
105+
If you want to view the pull request on {% data variables.product.prodname_dotcom_the_website %} instead of in the terminal, enter:
106+
107+
```copilot copy
108+
/pr view web
109+
```
110+
111+
This opens the pull request URL in your default browser.
112+
113+
## Creating a pull request
114+
115+
To create a pull request from your current branch, enter:
116+
117+
```copilot copy
118+
/pr create
119+
```
120+
121+
{% data variables.product.prodname_copilot_short %} ensures that all local commits are pushed to the remote branch, then creates the pull request. If a pull request template exists in the repository, {% data variables.product.prodname_copilot_short %} follows it when generating the pull request title and description.
122+
123+
If a pull request already exists for the current branch, `/pr create` updates the existing pull request instead of creating a new one.
124+
125+
### Adding instructions for pull request creation
126+
127+
You can append instructions after `/pr create` to guide {% data variables.product.prodname_copilot_short %}. For example:
128+
129+
```copilot copy
130+
/pr create prefix the PR title 'Project X: '
131+
```
132+
133+
## Fixing review feedback
134+
135+
To have {% data variables.product.prodname_copilot_short %} read and address review comments on your pull request, enter:
136+
137+
```copilot copy
138+
/pr fix feedback
139+
```
140+
141+
{% data variables.product.prodname_copilot_short %} fetches all review comment threads on the pull request, determines what changes are requested, applies the changes to your codebase, and commits and pushes the fixes. Actionable code change requests are prioritized over conversational comments.
142+
143+
## Resolving merge conflicts
144+
145+
To sync your branch with the base branch and resolve any merge conflicts, enter:
146+
147+
```copilot copy
148+
/pr fix conflicts
149+
```
150+
151+
{% data variables.product.prodname_copilot_short %} fetches the latest base branch, syncs your branch, resolves any conflicts, and pushes the result.
152+
153+
### Choosing a merge strategy
154+
155+
When resolving conflicts, {% data variables.copilot.copilot_cli_short %} needs to know whether to use a rebase or merge strategy. If you have not configured a preference, {% data variables.product.prodname_copilot_short %} prompts you to choose when you run a command that involves conflict resolution.
156+
157+
To set a default merge strategy so that you are not prompted each time, add the `mergeStrategy` setting to your configuration file. You can set this in your personal user settings for {% data variables.product.prodname_copilot_short %}, or in the repository settings.
158+
159+
* **User settings**: Add `"mergeStrategy": "rebase"` or `"mergeStrategy": "merge"` to your user-level configuration file (typically `~/.copilot/config.json`).
160+
* **Repository settings**: Add the same setting to `.github/copilot/settings.json` in your repository root.
161+
162+
## Fixing CI failures
163+
164+
To have {% data variables.product.prodname_copilot_short %} diagnose and fix failing CI checks, enter:
165+
166+
```copilot copy
167+
/pr fix ci
168+
```
169+
170+
{% data variables.product.prodname_copilot_short %} identifies the failing CI jobs, analyzes the logs to determine root causes, applies targeted fixes, and pushes them. It then re-checks the CI status and repeats the process until the checks pass or it determines that further progress is not possible.
171+
172+
If failures are unrelated to your branch changes, {% data variables.product.prodname_copilot_short %} notes this clearly so you can take appropriate action.
173+
174+
You can append additional context to help {% data variables.product.prodname_copilot_short %} focus on specific failures. For example:
175+
176+
```copilot copy
177+
/pr fix ci focus on test failures
178+
```
179+
180+
## Fixing all issues at once
181+
182+
To address all outstanding issues on a pull request in a single command, enter:
183+
184+
```copilot copy
185+
/pr fix
186+
```
187+
188+
This runs three phases in order:
189+
190+
1. **Review feedback** — Addresses all review comments.
191+
1. **Conflicts** — Syncs the branch with the base branch and resolves any conflicts.
192+
1. **CI failures** — Diagnoses and fixes failing CI checks.
193+
194+
## Automating the full pull request workflow
195+
196+
To have {% data variables.product.prodname_copilot_short %} manage the entire pull request process from creation to a fully green state, enter:
197+
198+
```copilot copy
199+
/pr auto
200+
```
201+
202+
If no pull request exists for the current branch, {% data variables.product.prodname_copilot_short %} creates one first. It then loops through the fix phases—review feedback, conflicts, and CI—repeating until there are no more review comments, no conflicts, and all CI checks pass.
203+
204+
You can append instructions to guide the pull request creation. For example:
205+
206+
```copilot copy
207+
/pr auto include migration notes in the description
208+
```
209+
210+
## Further reading
211+
212+
* [AUTOTITLE](/copilot/how-tos/copilot-cli/allowing-tools)
213+
* [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-command-reference)

content/copilot/reference/copilot-cli-reference/cli-command-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ COPILOT_GITHUB_TOKEN=github_pat_... copilot
138138
| `/model`, `/models [MODEL]` | Select the AI model you want to use. |
139139
| `/plan [PROMPT]` | Create an implementation plan before coding. |
140140
| `/plugin [marketplace\|install\|uninstall\|update\|list] [ARGS...]` | Manage plugins and plugin marketplaces. See [AUTOTITLE](/copilot/concepts/agents/copilot-cli/about-cli-plugins). |
141-
| `/pr [view\|create\|fix\|auto]` | Operate on pull requests for the current branch. |
141+
| `/pr [view\|create\|fix\|auto]` | Manage pull requests for the current branch. See [AUTOTITLE](/copilot/how-tos/copilot-cli/manage-pull-requests). |
142142
| `/remote` | Enable remote access to this session from {% data variables.product.prodname_dotcom_the_website %} and {% data variables.product.prodname_mobile %}. See [AUTOTITLE](/copilot/how-tos/copilot-cli/steer-remotely). |
143143
| `/rename [NAME]` | Rename the current session (auto-generates a name if omitted; alias for `/session rename`). |
144144
| `/research TOPIC` | Run a deep research investigation using {% data variables.product.github %} search and web sources. See [AUTOTITLE](/copilot/concepts/agents/copilot-cli/research). |

0 commit comments

Comments
 (0)