Skip to main content
Skip to content

GitHub.com 上使用 GitHub Copilot 的快速入门

无需离开 Copilot cloud agent,只需向 GitHub 提问并将编码任务交给它,即可更快地理解代码并完成工作。

GitHub Copilot 内置在 GitHub 中,因此无需安装任何内容即可使用。

本快速入门指南介绍如何提出有关代码的问题,以及如何将编码任务分配给 Copilot cloud agent。 大约需要十分钟的时间。

步骤 1:向 Copilot 询问某个文件

  1. 尝试这些提示浏览存储库中的 github/docs 特定文件。

    Copilot prompt
    In `github/docs`, look at `/package.json` and explain what this file does.
    
    Copilot prompt
    In `github/docs`, look at `/src/color-schemes/tests/color-mode-script.ts` and share how I could improve this code.
    

接下来,在所选存储库中打开一个文件,并询问 Copilot 有关该文件的问题。

  1. 导航到要浏览的任何存储库。 它不一定非得是你自己的。
  2. 打开存储库中的任何文件。
  3. Copilot单击文件视图右上角的图标()。
  4. 在提示框中,键入问题,然后按 Enter。 例如:
    • 解释此文件的作用。

    • 如何改进此代码?

    • 哪些测试将涵盖此函数?

    • 最后的改变是什么,为什么发生了?

Copilot 在聊天面板中进行响应。

  1. 请询问后续问题以进一步探索代码。 例如:
    •           <code id="3375012355">告诉我更多</code><a href="https://github.com/copilot?prompt=%E5%91%8A%E8%AF%89%E6%88%91%E6%9B%B4%E5%A4%9A" target="_blank" class="tooltipped tooltipped-n ml-1 copilot-prompt-long" aria-label="Run this prompt in Copilot Chat" aria-describedby="3375012355" style="text-decoration:none;"><svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-copilot" aria-hidden="true"><path d="M7.998 15.035c-4.562 0-7.873-2.914-7.998-3.749V9.338c.085-.628.677-1.686 1.588-2.065.013-.07.024-.143.036-.218.029-.183.06-.384.126-.612-.201-.508-.254-1.084-.254-1.656 0-.87.128-1.769.693-2.484.579-.733 1.494-1.124 2.724-1.261 1.206-.134 2.262.034 2.944.765.05.053.096.108.139.165.044-.057.094-.112.143-.165.682-.731 1.738-.899 2.944-.765 1.23.137 2.145.528 2.724 1.261.566.715.693 1.614.693 2.484 0 .572-.053 1.148-.254 1.656.066.228.098.429.126.612.012.076.024.148.037.218.924.385 1.522 1.471 1.591 2.095v1.872c0 .766-3.351 3.795-8.002 3.795Zm0-1.485c2.28 0 4.584-1.11 5.002-1.433V7.862l-.023-.116c-.49.21-1.075.291-1.727.291-1.146 0-2.059-.327-2.71-.991A3.222 3.222 0 0 1 8 6.303a3.24 3.24 0 0 1-.544.743c-.65.664-1.563.991-2.71.991-.652 0-1.236-.081-1.727-.291l-.023.116v4.255c.419.323 2.722 1.433 5.002 1.433ZM6.762 2.83c-.193-.206-.637-.413-1.682-.297-1.019.113-1.479.404-1.713.7-.247.312-.369.789-.369 1.554 0 .793.129 1.171.308 1.371.162.181.519.379 1.442.379.853 0 1.339-.235 1.638-.54.315-.322.527-.827.617-1.553.117-.935-.037-1.395-.241-1.614Zm4.155-.297c-1.044-.116-1.488.091-1.681.297-.204.219-.359.679-.242 1.614.091.726.303 1.231.618 1.553.299.305.784.54 1.638.54.922 0 1.28-.198 1.442-.379.179-.2.308-.578.308-1.371 0-.765-.123-1.242-.37-1.554-.233-.296-.693-.587-1.713-.7Z"></path><path d="M6.25 9.037a.75.75 0 0 1 .75.75v1.501a.75.75 0 0 1-1.5 0V9.787a.75.75 0 0 1 .75-.75Zm4.25.75v1.501a.75.75 0 0 1-1.5 0V9.787a.75.75 0 0 1 1.5 0Z"></path></svg></a><a href="https://github.com/copilot?prompt=%E5%91%8A%E8%AF%89%E6%88%91%E6%9B%B4%E5%A4%9A" target="_blank" class="tooltipped tooltipped-n ml-1 copilot-prompt-short" aria-label="Run prompt" aria-describedby="3375012355" style="text-decoration:none;"><svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-copilot" aria-hidden="true"><path d="M7.998 15.035c-4.562 0-7.873-2.914-7.998-3.749V9.338c.085-.628.677-1.686 1.588-2.065.013-.07.024-.143.036-.218.029-.183.06-.384.126-.612-.201-.508-.254-1.084-.254-1.656 0-.87.128-1.769.693-2.484.579-.733 1.494-1.124 2.724-1.261 1.206-.134 2.262.034 2.944.765.05.053.096.108.139.165.044-.057.094-.112.143-.165.682-.731 1.738-.899 2.944-.765 1.23.137 2.145.528 2.724 1.261.566.715.693 1.614.693 2.484 0 .572-.053 1.148-.254 1.656.066.228.098.429.126.612.012.076.024.148.037.218.924.385 1.522 1.471 1.591 2.095v1.872c0 .766-3.351 3.795-8.002 3.795Zm0-1.485c2.28 0 4.584-1.11 5.002-1.433V7.862l-.023-.116c-.49.21-1.075.291-1.727.291-1.146 0-2.059-.327-2.71-.991A3.222 3.222 0 0 1 8 6.303a3.24 3.24 0 0 1-.544.743c-.65.664-1.563.991-2.71.991-.652 0-1.236-.081-1.727-.291l-.023.116v4.255c.419.323 2.722 1.433 5.002 1.433ZM6.762 2.83c-.193-.206-.637-.413-1.682-.297-1.019.113-1.479.404-1.713.7-.247.312-.369.789-.369 1.554 0 .793.129 1.171.308 1.371.162.181.519.379 1.442.379.853 0 1.339-.235 1.638-.54.315-.322.527-.827.617-1.553.117-.935-.037-1.395-.241-1.614Zm4.155-.297c-1.044-.116-1.488.091-1.681.297-.204.219-.359.679-.242 1.614.091.726.303 1.231.618 1.553.299.305.784.54 1.638.54.922 0 1.28-.198 1.442-.379.179-.2.308-.578.308-1.371 0-.765-.123-1.242-.37-1.554-.233-.296-.693-.587-1.713-.7Z"></path><path d="M6.25 9.037a.75.75 0 0 1 .75.75v1.501a.75.75 0 0 1-1.5 0V9.787a.75.75 0 0 1 .75-.75Zm4.25.75v1.501a.75.75 0 0 1-1.5 0V9.787a.75.75 0 0 1 1.5 0Z"></path></svg></a>,让 Copilot 详细说明其上一条评论
      
    • 询问有关存储库的探索性问题
    • 解释拉取请求中的更改
    • 询问有关特定提交内容的问题

有关详细信息,请参阅“在GitHub中询问有关GitHub Copilot的问题”。

步骤 2:将问题分配给 Copilot

注意

Copilot cloud agent若要在本快速入门中使用,请升级到付费计划,例如Copilot Pro

如果你无法使用付费方案,也可以改为在你首选的编辑器中使用 Copilot 来了解其余步骤。 请参阅“在 IDE 中使用GitHub Copilot快速入门”。

Copilot cloud agent 可以自主处理编码任务。 分配议题是最简单的起步方式,并且 Copilot 会在完成时创建拉取请求。

  1. 在你具有写入权限的个人仓库中,从你的Copilot cloud agent中启用Copilot。

    • 若要改为为组织或企业中的存储库启用 Copilot cloud agent ,请参阅 启用 Copilot 了解进一步的说明。
  2. 找到想要 Copilot 处理的现有问题,或创建新问题。

  3. 打开议题。 在问题的右侧栏中,单击 “分配者”。

  4. 从分配者列表中单击Copilot

  5. (可选)在 “可选提示 ”字段中添加上下文,例如编码模式、要修改的文件或测试要求。

Copilot 使用问题标题、说明和现有注释。 在拉取请求打开后,将后续信息直接添加到拉取请求。

步骤 3:查看生成的拉取请求

当 Copilot 完成任务后,它会打开一个拉取请求并请求你审核。

  1. 打开 Copilot 创建的拉取请求。
  2. 查看差异并验证更改是否与预期内容匹配。
  3. 若要请求更改,请在对拉取请求的注释中提及 @copilot ,或直接将提交推送到分支。
  4. 当您对这些更改感到满意时,请合并拉取请求。

有关详细信息,请参阅“查看来自 Copilot 的输出”。

后续步骤