About using GitHub Copilot in the CLI
GitHub CLI 是用于从计算机的命令行使用 GitHub 的开源工具。 从命令行操作时,您可以使用 GitHub CLI 来节省时间并避免切换上下文。 For more information, see "关于 GitHub CLI."
GitHub Copilot in the CLI is an extension for GitHub CLI which provides a chat-like interface in the terminal that allows you to ask questions about the command line. You can ask Copilot in the CLI to suggest a command for your use case, with gh copilot suggest
, or to explain a command you're curious about, with gh copilot explain
.
Prerequisites
- To use Copilot in the CLI you must have an active GitHub Copilot subscription. For more information, see "关于 GitHub Copilot 的计费."
- To use Copilot in the CLI you must have GitHub CLI installed. 有关 GitHub CLI 的安装说明,请参阅 GitHub CLI 存储库。
Installing Copilot in the CLI
If you have not already done so, run gh auth login
to authenticate with your GitHub account.
To install the Copilot in the CLI extension, run gh extension install github/gh-copilot
.
To update Copilot in the CLI, run gh extension upgrade gh-copilot
.
Using Copilot in the CLI
To use gh
to work with GitHub Copilot, type gh copilot SUBCOMMAND
. Additionally, you can use gh copilot --help
for general help or gh copilot SUBCOMMAND --help
for help with a specific subcommand.
Asking Copilot in the CLI to explain a command
You can ask Copilot in the CLI to explain a command for you by running:
gh copilot explain
Alternatively, you can add the command you want explained directly to the prompt:
gh copilot explain "sudo apt-get"
Copilot in the CLI can help by explaining what a command does in plain language. This makes it easier for you to understand the command's purpose and how it works for a specific example. You don't need to go through the command's documentation because the explanation includes information about what the command takes as input and produces as output, and provides practical examples.
Asking Copilot in the CLI to suggest a command
You can ask Copilot in the CLI to suggest a command for you by running:
gh copilot suggest
This will start an interactive experience to get the command you need. Copilot in the CLI aims to suggest commands that help you perform the tasks you’re trying to complete. To help Copilot in the CLI provide better suggestions, you can specify the type of command you are looking for (generic, git
or gh
).
If you already know what command you need, you can also include that in the prompt. For example, if you want to install Git, you can ask Copilot in the CLI to suggest a command for you:
gh copilot suggest "Install git"
If the result isn’t quite what you’re looking for, you can keep revising your question until the returned command meets your expectations. You can do this by selecting the Revise command option.
Once you’ve generated the perfect command for your task, you can easily copy it to your clipboard to run it wherever you need by selecting the Copy to clipboard option.
Sharing feedback about Copilot in the CLI
If you encounter any issues or limitations with Copilot in the CLI, you can provide feedback by selecting the Rate response option in Copilot in the CLI.