π Source: How-to-Install Copilot in the CLI
- You need an active GitHub Copilot subscription or access via your organization. Copilot is available in both personal and team/enterprise accounts.
- See Getting access to Copilot.
- The GitHub CLI provides a command-line interface to interact with GitHub, allowing you to manage issues, pull requests, and repositories from the terminal.
- For installation instructions, see the GitHub CLI repository.
- If your organization has disabled Copilot in the CLI, you will not be able to use it.
- Check with your organization's GitHub administrator to ensure Copilot is enabled for your environment.
- See Managing policies and features for Copilot.
Run the following command to log in to your GitHub account and authorize the GitHub CLI to use your account for Copilot features.
gh auth login
This command installs the GitHub Copilot CLI extension, which allows you to interact with Copilot directly from your terminal.
gh extension install github/gh-copilot
If an update to the extension is available, use this command to upgrade it:
gh extension upgrade gh-copilot
- π§βπ» Using GitHub Copilot in the CLI
- ποΈπ» Customizing GitHub Copilot in the CLI
- Access to GitHub Copilot: See What is GitHub Copilot?
- GitHub CLI Installed: See GitHub CLI installation
- Copilot in the CLI Extension Installed: See Installing GitHub Copilot in the CLI
If you have access to GitHub Copilot via your organization or enterprise, you will not be able to use Copilot in the CLI if your administrator has disabled it. See Managing policies and features for Copilot.
Run gh copilot explain followed by the command you want explained.
Example:
If you're unsure about a command like sudo apt-get, Copilot can explain what it does and how to use it.
gh copilot explain "sudo apt-get"
Run gh copilot suggest followed by a description of what you want to do.
Example: If you want to undo the last Git commit, Copilot can suggest the appropriate command.
gh copilot suggest "Undo the last commit"
Copilot in the CLI will interact with you to refine the suggestion or help you choose the best approach. You can also execute the suggested command directly from the interactive session.
To set up aliases for Bash, add this to your .bashrc file:
echo 'eval "$(gh copilot alias -- bash)"' >> ~/.bashrc
For PowerShell users, use this command to set up aliases:
$GH_COPILOT_PROFILE = Join-Path -Path $(Split-Path -Path $PROFILE -Parent) -ChildPath "gh-copilot.ps1"
gh copilot alias -- pwsh | Out-File ( New-Item -Path $GH_COPILOT_PROFILE -Force )
echo ". \`"$GH_COPILOT_PROFILE\`"" >> $PROFILE
To set up aliases for Zsh, add this to your .zshrc file:
echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc
When using ghcs, Copilot will ask you to confirm before executing a command. You can change this confirmation behavior by running the following command:
gh copilot config
Then, select: "Default value for confirming command execution".
By default, Copilot sends anonymous usage data to GitHub to help improve the product. You can opt out of this data collection.
{
"platform": "darwin",
"architecture": "arm64",
"version": "0.3.0-beta",
"custom_event": "true",
"event_parent_command": "explain",
"event_name": "Explain",
"sha": "...",
"thread_id": "..."
}
To opt in or out of data collection:
gh copilot config
Then, select: "Optional Usage Analytics"