1
0
mirror of synced 2025-12-19 09:57:42 -05:00
Files
docs/content/copilot/how-tos/use-copilot-agents/coding-agent/create-a-pr.md
2025-10-10 07:32:37 +00:00

24 KiB

title, shortTitle, intro, product, versions, topics, redirect_from, contentType
title shortTitle intro product versions topics redirect_from contentType
Asking GitHub Copilot to create a pull request Create a PR You can ask {% data variables.product.prodname_copilot_short %} to create a pull request from many places, including {% data variables.product.prodname_github_issues %}, the agents panel, {% data variables.copilot.copilot_chat_short %}, the {% data variables.product.prodname_cli %}, and agentic coding tools and IDEs with Model Context Protocol (MCP) support. {% data reusables.gated-features.copilot-coding-agent %}<br><a href="https://github.com/features/copilot/plans?ref_product=copilot&ref_type=engagement&ref_style=button" target="_blank" class="btn btn-primary mt-3 mr-3 no-underline"><span>Sign up for {% data variables.product.prodname_copilot_short %}</span> {% octicon "link-external" height:16 %}</a>
feature
copilot
Copilot
/copilot/using-github-copilot/using-copilot-coding-agent-to-work-on-tasks/asking-copilot-to-create-a-pull-request
/copilot/using-github-copilot/using-copilot-coding-agent-to-work-on-issues/asking-copilot-to-create-a-pull-request
/copilot/using-github-copilot/coding-agent/asking-copilot-to-create-a-pull-request
/copilot/how-tos/agents/copilot-coding-agent/asking-copilot-to-create-a-pull-request
/copilot/how-tos/agents/copilot-coding-agent/create-a-pr
/copilot/how-tos/agents/coding-agent/create-a-pr
/copilot/using-github-copilot/using-copilot-coding-agent-to-work-on-tasks/using-copilot-to-work-on-an-issue
/copilot/using-github-copilot/using-copilot-coding-agent-to-work-on-issues/using-copilot-to-work-on-an-issue
/early-access/copilot/coding-agent/using-copilot-coding-agent
/copilot/using-github-copilot/coding-agent/using-copilot-to-work-on-an-issue
/copilot/how-tos/agents/copilot-coding-agent/using-copilot-to-work-on-an-issue
/copilot/how-tos/agents/copilot-coding-agent/assign-copilot-to-an-issue
/copilot/how-tos/agents/coding-agent/assign-copilot-to-an-issue
/copilot/how-tos/use-copilot-agents/coding-agent/assign-copilot-to-an-issue
how-tos

Note

For an overview of {% data variables.copilot.copilot_coding_agent %}, see AUTOTITLE.

Introduction

You can ask {% data variables.product.prodname_copilot_short %} to work on a task from:

{% data variables.product.prodname_copilot_short %} will start working on the task, raise a pull request, then request a review from you when it's finished working. For more information, see AUTOTITLE.

Assigning an issue to {% data variables.product.prodname_copilot_short %}

You can ask {% data variables.product.prodname_copilot_short %} to start working on an issue by assigning the issue to {% data variables.product.prodname_copilot_short %}.

You can assign an issue to {% data variables.product.prodname_copilot_short %}:

Assigning an issue to {% data variables.product.prodname_copilot_short %} on {% data variables.product.prodname_dotcom_the_website %}

{% data reusables.repositories.navigate-to-repo %} {% data reusables.repositories.sidebar-issues %}

  1. Open the issue that you want to assign to {% data variables.product.prodname_copilot_short %}.

  2. In the right side menu, click Assignees.

    Screenshot of the right sidebar of an issue. A header, labeled "Assignees", is outlined in dark orange.

  3. Click Copilot from assignees list.

    Screenshot of "Assignees" window on an issue. Copilot is available in the list.

    Additional options are displayed.

    Screenshot of "Assign to Copilot" dialog showing options for target repository, starting branch and additional instructions.

  4. In the Optional prompt field you can add specific guidance for {% data variables.product.prodname_copilot_short %}. Add any context, constraints, or specific requirements that will help {% data variables.product.prodname_copilot_short %} to understand and complete the task.

    For example, you might include instructions about specific coding patterns or frameworks to use, testing requirements, code style preferences, files or directories that should or shouldn't be modified.

    In addition to the details you supply here, {% data variables.product.prodname_copilot_short %} will use any custom instructions that have been configured for the target repository. See AUTOTITLE.

  5. You can use the dropdown menus in the dialog to change the repository that {% data variables.product.prodname_copilot_short %} will work in and the branch that it will branch off from.

    Note

    If you don't specify a repository, {% data variables.product.prodname_copilot_short %} will work in the same repository as the issue. If you don't specify a branch, {% data variables.product.prodname_copilot_short %} will work from the default branch of the selected repository.

    Tip

    When you assign an issue to {% data variables.product.prodname_copilot_short %}, it gets sent the issue title, description, any comments that currently exist, and any additional instructions you provide. After assigning the issue, {% data variables.product.prodname_copilot_short %} will not be aware of, and therefore won't react to, any further comments that are added to the issue. If you have more information, or changes to the original requirement, add this as a comment in the pull request that {% data variables.product.prodname_copilot_short %} raises.

You can also assign issues to {% data variables.product.prodname_copilot_short %} from other places on {% data variables.product.prodname_dotcom_the_website %}:

  • From the list of issues on a repository's {% octicon "issue-opened" aria-hidden="true" aria-label="issue-opened" %} Issues page.
  • When viewing an issue in {% data variables.product.github %} {% data variables.projects.projects_v2_caps %}.

Assigning an issue to {% data variables.product.prodname_copilot_short %} on {% data variables.product.prodname_mobile %}

  1. In {% data variables.product.prodname_mobile %}, navigate to the repository that contains the issue you want to assign to {% data variables.product.prodname_copilot_short %}.
  2. Click Issues.
  3. Open the issue that you want to assign to {% data variables.product.prodname_copilot_short %}.
  4. Tap the {% octicon "info" aria-label="information" %} icon.
  5. Beside "Assignees", tap Edit.
  6. Beside "{% data variables.product.prodname_copilot_short %}", click the plus sign.
  7. Click Done.

Assigning an issue to {% data variables.product.prodname_copilot_short %} via the {% data variables.product.github %} API

You can assign issues to {% data variables.product.prodname_copilot_short %} using the GraphQL API.

Creating and assigning a new issue

  1. Make sure you're authenticating with the API using a user token, for example a {% data variables.product.pat_generic %} or a {% data variables.product.prodname_github_app %} user-to-server token.

  2. Verify that {% data variables.copilot.copilot_coding_agent %} is enabled in the repository by checking if the repository's suggestedActors in the GraphQL API includes {% data variables.product.prodname_copilot_short %}. Replace octo-org with the repository owner, and octo-repo with the repository name.

    query {
      repository(owner: "octo-org", name: "octo-repo") {
        suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
          nodes {
            login
            __typename
    
            ... on Bot {
              id
            }
    
            ... on User {
              id
            }
          }
        }
      }
    }
    

    If {% data variables.copilot.copilot_coding_agent %} is enabled for the user and in the repository, the first node returned from the query will have the login value copilot-swe-agent.

  3. Make a note of the id value of this login.

  4. Fetch the GraphQL global ID of the repository you want to create the issue in, replacing octo-org with the repository owner, and octo-repo with the repository name.

    query {
      repository(owner: "octo-org", name: "octo-repo") {
        id
      }
    }
    
  5. Create the issue with the createIssue mutation. Replace REPOSITORY_ID with the ID returned from the previous step, and BOT_ID with the ID returned from the step before that.

    mutation {
      createIssue(input: {repositoryId: "REPOSITORY_ID", title: "Implement comprehensive unit tests", body: "DETAILS", assigneeIds: ["BOT_ID"]}) {
        issue {
          id
          title
          assignees(first: 10) {
            nodes {
              login
            }
          }
        }
      }
    }
    

Assigning an existing issue

  1. Make sure you're authenticating with the API using a user token, for example a {% data variables.product.pat_generic %} or a {% data variables.product.prodname_github_app %} user-to-server token.

  2. Verify that {% data variables.copilot.copilot_coding_agent %} is enabled in the repository by checking if the repository's suggestedActors in the GraphQL API includes {% data variables.product.prodname_copilot_short %}. Replace octo-org with the repository owner, and octo-repo with the repository name.

    query {
      repository(owner: "monalisa", name: "octocat") {
        suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
          nodes {
            login
            __typename
    
            ... on Bot {
              id
            }
    
            ... on User {
              id
            }
          }
        }
      }
    }
    

    If {% data variables.copilot.copilot_coding_agent %} is enabled for the user and in the repository, the first node returned from the query will have the login value copilot-swe-agent.

  3. Fetch the GraphQL global ID of the issue you want to assign to {% data variables.product.prodname_copilot_short %}, replacing monalisa with the repository owner, octocat with the name and 9000 with the issue number.

    query {
      repository(owner: "monalisa", name: "octocat") {
        issue(number: 9000) {
          id
          title
        }
      }
    }
    
  4. Assign the existing issue to {% data variables.product.prodname_copilot_short %} using the replaceActorsForAssignable mutation. Replace ISSUE_ID with the ID returned from the previous step, and BOT_ID with the ID returned from the step before that.

    mutation {
      replaceActorsForAssignable(input: {assignableId: "ISSUE_ID", actorIds: ["BOT_ID"]}) {
        assignable {
          ... on Issue {
            id
            title
            assignees(first: 10) {
              nodes {
                login
              }
            }
          }
        }
      }
    }
    

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from the agents panel or page

You can ask {% data variables.product.prodname_copilot_short %} to open a pull request from either the agents panel or the agents page. The only difference is the entry point - once you see the "New agent task" form, the steps are the same.

  1. Open the agents panel or page:

    • Open the agents panel: Click {% octicon "agent" aria-label="The Agents icon" %} in the navigation bar at the top right of {% data variables.product.github %}.
    • Navigate to the agents page: Go to github.com/copilot/agents. You can also get here by opening the agents panel, then clicking View all.

{% data reusables.copilot.coding-agent.new-agent-task-form-instructions %}

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from the "New repository" page

When creating a new repository, you can ask {% data variables.product.prodname_copilot_short %} to seed the new repository by entering a prompt.

{% data reusables.repositories.create_new %} {% data reusables.repositories.owner-drop-down %}

  1. In the Prompt field, enter a prompt describing what you want {% data variables.product.prodname_copilot_short %} to build.

    For example, Create a Rust CLI for converting CSV spreadsheets to Markdown {% data reusables.repositories.create-repo %}

    {% data variables.product.prodname_copilot_short %} will immediately open a draft pull request. {% data variables.product.prodname_copilot_short %} will work on the task and push changes to its pull request, then add you as a reviewer when it has finished, triggering a notification.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from {% data variables.copilot.copilot_chat_short %} in {% data variables.product.prodname_vscode %}

  1. Install the {% data variables.product.github %} Pull Requests extension for {% data variables.product.prodname_vscode %}.

  2. Open {% data variables.copilot.copilot_chat %} in {% data variables.product.prodname_vscode %}.

  3. Type a prompt explaining what you want {% data variables.product.prodname_copilot_short %} to do, and add #copilotCodingAgent to the prompt.

    For example, Put backticks around file names and variables in output #copilotCodingAgent

    Tip

    • To help {% data variables.product.prodname_copilot_short %}, you can select the relevant line(s) of code before submitting your prompt.
  4. Submit your prompt.

    {% data variables.product.prodname_copilot_short %} will typically do some research and context-gathering in {% data variables.product.prodname_vscode %}, and then will ask you to confirm that you want to use the coding agent to create a pull request.

  5. Click Continue.

    {% data variables.product.prodname_copilot_short %} will push up any local changes, start a new session and respond with a link to the pull request it creates. It will work on the task and push changes to the pull request, and then add you as a reviewer when it has finished, triggering a notification.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from {% data variables.copilot.copilot_chat_short %} in other IDEs

  1. Open {% data variables.copilot.copilot_chat %} in {% data variables.product.prodname_vs %} or JetBrains IDEs.

  2. Type a prompt, starting with @github, asking {% data variables.product.prodname_copilot_short %} to create a pull request, and giving details of what you want {% data variables.product.prodname_copilot_short %} to change.

    For example, @github Create a PR to put backticks around file names and variables in output.

    Tip

    • To help {% data variables.product.prodname_copilot_short %}, you can select the relevant line(s) of code before submitting your prompt.
    • From {% data variables.copilot.copilot_chat_short %}, you can ask {% data variables.product.prodname_copilot_short %} to open a pull request using a specific branch as the base branch by including it in your prompt.
  3. Submit your prompt.

    {% data variables.product.prodname_copilot_short %} asks you to confirm that you want to use the coding agent to create a pull request.

  4. Click Allow.

    {% data variables.product.prodname_copilot_short %} will start a new session and respond with a link to the pull request it creates. It will work on the task and push changes to the pull request, and then add you as a reviewer when it has finished, triggering a notification.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from {% data variables.copilot.copilot_chat_short %} in {% data variables.product.prodname_dotcom_the_website %}

  1. Open {% data variables.copilot.copilot_chat %} on {% data variables.product.prodname_dotcom_the_website %}.

  2. Type a prompt asking {% data variables.product.prodname_copilot_short %} to create a pull request, and giving details of what you want {% data variables.product.prodname_copilot_short %} to change.

    For example, Create a PR in monalisa/bookstore to put backticks around file names and variables in output.

    Tip

    • You can ask {% data variables.product.prodname_copilot_short %} to open a pull request using a specific branch as the base branch by including it in your prompt.
  3. Submit your prompt.

    {% data variables.product.prodname_copilot_short %} asks you to confirm that you want to use the coding agent to create a pull request.

  4. Click Allow.

    {% data variables.product.prodname_copilot_short %} will start a new session and respond with a link to the pull request it creates. It will work on the task and push changes to the pull request, and then add you as a reviewer when it has finished, triggering a notification.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from {% data variables.product.prodname_mobile %}

  1. In {% data variables.product.prodname_mobile %}, navigate to the repository where you want to create a pull request.

  2. Tap the {% octicon "copilot" aria-hidden="true" aria-label="Copilot" %} icon in the bottom right corner of the screen.

  3. Enter a prompt to ask {% data variables.product.prodname_copilot_short %} to create a pull request.

    For example: Create a pull request to ....

    {% data variables.product.prodname_copilot_short %} responds with a brief summary of the task it will perform, asking for your confirmation before it proceeds.

  4. Check that {% data variables.product.prodname_copilot_short %} has interpreted your prompt correctly, then tap Accept or Dismiss.

    {% data variables.product.prodname_copilot_short %} creates a pull request and gives you a link to it. It will work on the task and push changes to the pull request, and then add you as a reviewer when it has finished, triggering a notification.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from the {% data variables.product.prodname_cli %}

Note

The agent-task command set is only available in v2.80.0 or later of the {% data variables.product.prodname_cli %}. This command set is a {% data variables.release-phases.public_preview %} and is subject to change.

You can start a new {% data variables.copilot.copilot_coding_agent %} session with the gh agent-task create command in the {% data variables.product.prodname_cli %}.

When you run the command without any arguments, you are asked to enter a prompt. {% data variables.copilot.copilot_coding_agent %} acts on the prompt and opens a pull request in the current repository.

You can use command line options to:

  • Provide the prompt (gh agent-task create "Example prompt")
  • Choose a base branch, instead of using the repository's default branch (--base)
  • Select a repository, instead of targeting the current repository (--repo)
  • Follow the session log in real time (--follow)

To see all of the available options, run gh agent-task create --help.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from the {% data variables.product.github %} MCP server

Note

  • This capability is only available on the remote {% data variables.product.github %} MCP server and host applications where remote MCP servers are supported.
  1. Install the {% data variables.product.github %} MCP server in your preferred IDE or agentic coding tool. See AUTOTITLE.

  2. Ensure the create_pull_request_with_copilot tool is enabled.

  3. Open chat.

  4. Type a prompt asking {% data variables.product.prodname_copilot_short %} to create a pull request, with the details of what you want to change.

    For example, Open a PR in my repository to expand unit test coverage.

    Tip

    • You can ask {% data variables.product.prodname_copilot_short %} to open a pull request using a specific branch as the base branch by including it in your prompt.
  5. Submit your prompt.

    {% data variables.product.prodname_copilot_short %} will start a new session, open a draft pull request and work on the task in the background. As it works, it will push changes to the pull request, and once it has finished, it will add you as a reviewer. In most cases, the MCP host will show you the URL of the created pull request.

Asking {% data variables.product.prodname_copilot_short %} to create a pull request from Raycast

{% data reusables.copilot.coding-agent.raycast-intro %}

{% data reusables.copilot.coding-agent.raycast-setup %}

  1. Open Raycast, search for "{% data variables.product.prodname_copilot_short %}," find the Create Task command, then press Enter.

  2. Click Sign in with {% data variables.product.github %}, then complete the authentication flow. Raycast will re-open.

  3. Type a prompt describing what you want {% data variables.product.prodname_copilot_short %} to do.

    For example, Implement a user friendly message for common errors.

  4. Select the repository you want {% data variables.product.prodname_copilot_short %} to work in.

  5. Optionally, select a base branch for {% data variables.product.prodname_copilot_short %}'s pull request. {% data variables.product.prodname_copilot_short %} will create a new branch based on this branch, then push the changes to a pull request targeting that branch.

  6. Press Command+Enter to start the task.

    {% data variables.product.prodname_copilot_short %} will start a new session. {% data variables.product.prodname_copilot_short %} will work on the task and push changes to its pull request, then add you as a reviewer when it has finished, triggering a notification.

Note

If you are unable to select a specific repository when starting a task, the organization that owns the repository may have enabled {% data variables.product.prodname_oauth_app %} access restrictions. To learn how to request approval for the "{% data variables.product.prodname_copilot %} for Raycast" {% data variables.product.prodname_oauth_app %}, see AUTOTITLE.

Monitoring progress

You can view your current and past {% data variables.product.prodname_copilot_short %} sessions from the agents panel, agents page and {% data variables.product.prodname_vscode %}. See AUTOTITLE.

Further reading