|
1 | | -GitHub Copilot isn't just a tool for writing code in your favorite IDE; it’s also a powerful assistant that can help streamline your command-line workflows. By integrating with the GitHub CLI, Copilot can provide explanations for unfamiliar commands, suggest commands based on your needs, and even execute them on your behalf. Whether you're new to the command line or a seasoned user, Copilot can enhance your productivity by offering intelligent suggestions and simplifying complex tasks. |
| 1 | +GitHub Copilot isn’t just for Integrated Development Environments(IDEs)—it’s now a powerful assistant in your terminal. **GitHub Copilot CLI** brings Copilot directly into the command line, where it can explain commands, suggest shell commands from natural language, and help you work safely and interactively with your files and projects. |
| 2 | + |
| 3 | +Copilot CLI uses GitHub authentication and runs independently from GitHub CLI, though it uses your existing credentials. Whether you’re new to the command line or an experienced developer, Copilot CLI reduces guesswork and speeds up everyday workflows. |
2 | 4 |
|
3 | 5 | This unit covers: |
4 | 6 |
|
5 | | -- Guiding you through the common GitHub Copilot CLI commands, |
6 | | -- Exploring configuration options enabling you to make the most of GitHub Copilot directly from your terminal. |
| 7 | +* Installing and running GitHub Copilot CLI |
| 8 | +* Interactive sessions in the terminal |
| 9 | +* Slash commands and natural language input |
| 10 | +* Configuration and options |
7 | 11 |
|
| 12 | +## Installing and launching Copilot CLI |
8 | 13 |
|
9 | | -## Common commands |
10 | | -Once you have Copilot set up in the CLI, here are some frequently used commands for interacting with it: |
| 14 | +Install via **Homebrew** on macOS and Linux: |
11 | 15 |
|
12 | | -- **Getting command explanations**: |
13 | | - - If you're unsure about what a specific command does, you can ask Copilot to explain it. For instance: |
| 16 | +```bash |
| 17 | +brew install copilot-cli |
| 18 | +``` |
14 | 19 |
|
15 | | - ```shell |
16 | | - gh copilot explain "sudo apt-get" |
17 | | - ``` |
| 20 | +Or use the **official install script**: |
18 | 21 |
|
19 | | - :::image type="content" source="../media/copilot-explain-in-cli.png" alt-text="Screenshot of copilot explain in cli."::: |
| 22 | +```bash |
| 23 | +curl -fsSL https://gh.io/copilot-install | bash |
| 24 | +``` |
20 | 25 |
|
21 | | - This command provides you with a detailed explanation of the provided command. |
| 26 | +Launch Copilot CLI in **interactive mode**: |
22 | 27 |
|
23 | | -- **Getting command suggestions**: |
24 | | - - Need help with constructing a command? You can ask Copilot to suggest a command based on what you want to accomplish: |
25 | | - ```shell |
26 | | - gh copilot suggest "Undo the last commit" |
27 | | - ``` |
| 28 | +```bash |
| 29 | +copilot |
| 30 | +``` |
28 | 31 |
|
29 | | - :::image type="content" source="../media/copilot-suggest-in-cli.png" alt-text="Screenshot of copilot suggest in cli."::: |
| 32 | +It displays see a welcome banner and a prompt: |
30 | 33 |
|
31 | | - Copilot starts an interactive session to clarify your request and suggest the best command. |
| 34 | +:::image type="content" source="../media/copilot-cli-banner.png" alt-text="Screenshot of Copilot interactive mode banner."::: |
32 | 35 |
|
33 | | -- **Executing suggested commands**: |
34 | | -After receiving a suggestion, you can choose the `Execute command` option. This copies the command to your clipboard. You can also allow Copilot to execute commands on your behalf only if you configure the `ghcs` alias: |
| 36 | +On first launch, Copilot asks whether you trust the files in the current folder. Copilot may read, modify, or execute files in this directory during the session, so only proceed in locations you trust. |
35 | 37 |
|
36 | | - ``` |
37 | | - ghcs suggest "What command to see running docker containers" |
38 | | - ``` |
| 38 | +:::image type="content" source="../media/copilot-cli-trust-files.png" alt-text="Screenshot of Copilot interactive specify directory."::: |
39 | 39 |
|
40 | | - :::image type="content" source="../media/executing-suggested-command-copilot-suggest-in-cli.png" lightbox="../media/executing-suggested-command-copilot-suggest-in-cli.png" alt-text="Screenshot of executing suggested command copilot suggest in cli."::: |
| 40 | +You can use the `@` to select a specific file you want to work with as context. |
41 | 41 |
|
42 | | -- **Revise suggested command**: |
43 | | - To give GitHub Copilot CLI to rework or revise a command to make it better or more suited to your expectations, use the "Revise command" option along with your feedback. |
| 42 | +:::image type="content" source="../media/copilot-cli-select-file.png" alt-text="Screenshot of selecting a file in copilot interactive mode."::: |
44 | 43 |
|
45 | | - :::image type="content" source="../media/revising-suggested-command-copilot-suggest-in-cli.png" alt-text="Screenshot of revising suggested command copilot suggest in cli."::: |
| 44 | +Inside an interactive session, you can: |
46 | 45 |
|
| 46 | +* Use **slash commands** (`/command`) to control the session and configure Copilot CLI. |
| 47 | +* Type **natural language prompts** to explain, suggest, or revise commands. |
47 | 48 |
|
48 | | -## Configuration options |
| 49 | +For **one-shot prompts** without entering full interactive mode: |
49 | 50 |
|
50 | | -To make the most out of Copilot in the CLI, you may want to configure certain settings: |
| 51 | +```bash |
| 52 | +copilot -i "explain brew install git" |
| 53 | +copilot -i "suggest find large files and delete them" |
| 54 | +``` |
51 | 55 |
|
52 | | -- **Alias Configuration**: |
53 | | - If you want Copilot to execute commands on your behalf directly, you need to set up the `ghcs` alias. Using an alias allows you to bypass copying and pasting commands manually, and instead Copilot does it for you. |
| 56 | +## Common slash commands |
54 | 57 |
|
55 | | - To configure the `ghcs` alias, run the following commands: |
| 58 | +Slash commands are explicit session-control commands. Here are the most common ones: |
56 | 59 |
|
57 | | - For bash: |
| 60 | +| Slash Command | Description | |
| 61 | +| ---------------------- | ----------------------------------------------------- | |
| 62 | +| `/help` | Show available commands and options | |
| 63 | +| `/explain <command>` | Ask Copilot to explain any shell command | |
| 64 | +| `/suggest <task>` | Ask Copilot to suggest a shell command for a task | |
| 65 | +| `/revise` | Revise the last suggestion based on your instructions | |
| 66 | +| `/feedback` | Submit feedback on a response or suggestion | |
| 67 | +| `/exit` | Exit interactive mode | |
| 68 | +| `/model <model>` | Select which AI model to use | |
| 69 | +| `/theme [auto|dark|light]` | Change terminal theme | |
| 70 | +| `/skills` | Manage skills for enhanced capabilities | |
| 71 | +| `/mcp` | Manage MCP server configuration | |
| 72 | +| `/list-dirs` | Show allowed directories for file operations | |
| 73 | +| `/reset-allowed-tools` | Reset allowed tools list | |
58 | 74 |
|
59 | | - ``` |
60 | | - echo 'eval "$(gh copilot alias -- bash)"' >> ~/.bashrc |
61 | | - ``` |
| 75 | +> Slash commands cannot be replaced with natural language prompts. They are the only way to control session settings and configuration. |
62 | 76 |
|
63 | | - For PowerShell: |
| 77 | +## Example workflows |
64 | 78 |
|
65 | | - ``` |
66 | | - $GH_COPILOT_PROFILE = Join-Path -Path $(Split-Path -Path $PROFILE -Parent) -ChildPath "gh-copilot.ps1" |
67 | | - gh copilot alias -- pwsh | Out-File ( New-Item -Path $GH_COPILOT_PROFILE -Force ) |
68 | | - echo ". `"$GH_COPILOT_PROFILE`"" >> $PROFILE |
69 | | - ``` |
| 79 | +### 1. Explain a command |
70 | 80 |
|
71 | | - For Mac terminal or Zsh: |
| 81 | +```text |
| 82 | +> Explain what `git reset --hard HEAD` does |
| 83 | +``` |
72 | 84 |
|
73 | | - ``` |
74 | | - echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc |
75 | | - ``` |
| 85 | +Copilot will provide a detailed explanation. |
| 86 | + |
| 87 | +:::image type="content" source="../media/copilot-explain-in-cli.png" alt-text="Screenshot of Copilot CLI explaining a command in interactive mode."::: |
| 88 | + |
| 89 | +### 2. Suggest a command |
| 90 | + |
| 91 | +```text |
| 92 | +> Find and delete all .log files in my home folder |
| 93 | +``` |
| 94 | + |
| 95 | +Copilot generates a command suggestion, and prompt you to execute it if you're satisfied with its suggestions. |
| 96 | + |
| 97 | +:::image type="content" source="../media/copilot-cli-suggest-command.png" alt-text="Screenshot of Copilot CLI suggesting a command in interactive mode."::: |
76 | 98 |
|
77 | | -- **Feedback mechanism**: |
78 | | - Copilot encourages user feedback to improve its suggestions. You can rate the quality of a suggestion by selecting the `Rate response` option after Copilot provides you with a command. |
| 99 | +### 3. Revise a suggestion |
79 | 100 |
|
80 | | - :::image type="content" source="../media/rating-suggested-command-copilot-suggest-in-cli.png" alt-text="Screenshot of rating suggested command copilot suggest in cli."::: |
| 101 | +After receiving a suggestion, you can type a follow-up prompt to revise the suggested command: |
| 102 | + |
| 103 | +```text |
| 104 | +> Include only files modified in the last 7 days |
| 105 | +``` |
| 106 | +:::image type="content" source="../media/copilot-cli-revise-suggestion.png" alt-text="Screenshot of Copilot CLI improving a suggestion based on the follow-up prompt."::: |
| 107 | + |
| 108 | +### 4. Provide feedback |
| 109 | + |
| 110 | +After a response or suggestion: |
| 111 | + |
| 112 | +```text |
| 113 | +> /feedback |
| 114 | +``` |
| 115 | +:::image type="content" source="../media/copilot-cli-provide-feedback.png" alt-text="Screenshot of using the /feedack slash command in Copilot CLI interactive mode."::: |
| 116 | + |
| 117 | +Copilot prompts you to choose the kind of feedback you want to send, then navigate you to the appropriate form to complete your feedback. |
| 118 | + |
| 119 | +### 5. Exit interactive mode |
| 120 | + |
| 121 | +```text |
| 122 | +> /exit |
| 123 | +``` |
| 124 | + |
| 125 | +## Configuration options |
| 126 | + |
| 127 | +In Copilot CLI, configuration is handled via: |
| 128 | + |
| 129 | +1. **Slash commands** inside interactive mode |
| 130 | + |
| 131 | + * `/model` choose AI model |
| 132 | + * `/theme` change terminal theme |
| 133 | + * `/skills` manage enhanced capabilities |
| 134 | + * `/reset-allowed-tools` reset tools |
| 135 | + * `/list-dirs` view allowed directories |
| 136 | + * `/mcp` MCP server settings |
| 137 | + |
| 138 | +2. **`copilot configure` command** (non-interactive mode) |
| 139 | + |
| 140 | + ```bash |
| 141 | + copilot configure |
| 142 | + ``` |
81 | 143 |
|
82 | | -- **Organizational settings**: |
83 | | - If you're using Copilot within an organization your access to certain features may be governed by your organization's policies. Administrators can enable or disable Copilot's capabilities within the CLI. |
| 144 | + * Lets you set global preferences like default model, theme, or optional usage analytics. |
| 145 | + * Feedback settings and organizational access can be managed here. |
84 | 146 |
|
85 | | - For further customization and detailed configuration so you can optimize Copilot's functionality for your specific needs, refer to the [GitHub documentation](https://docs.github.com/en/copilot). |
| 147 | +Refer to the [official GitHub Copilot CLI documentation](https://github.com/github/copilot-cli) for full configuration options. |
86 | 148 |
|
87 | | -- **Data handling**: |
88 | | - GitHub Copilot CLI doesn't retain your prompts, but it keeps your usage analytics. You can configure whether you want GitHub Copilot to keep and use your usage data to improve the product. Enter the command ` gh copilot config` , select "Optional Usage Analytics", then select "No" if you want to opt out. |
| 149 | +### Tips for effective use |
89 | 150 |
|
90 | | - :::image type="content" source="../media/configure-usage-data-setting-in-cli.png" alt-text="Screenshot of configure usage data setting in cli."::: |
| 151 | +* Use **interactive mode (`copilot`)** for exploratory tasks. |
| 152 | +* Use **one-shot mode (`copilot -i`)** for quick answers. |
| 153 | +* **Natural language input works**—you don’t always need slash commands. |
| 154 | +* Always review commands before execution. |
| 155 | +* Combine Copilot CLI with GitHub CLI (`gh`) for repository and issue management. |
| 156 | +* Use **slash commands** when you want structured actions or feedback. |
0 commit comments