Skip to content

Instantly share code, notes, and snippets.

@nine1one
Last active August 5, 2025 05:38
Show Gist options
  • Select an option

  • Save nine1one/27457630cf223dea24c21b42c613e6e9 to your computer and use it in GitHub Desktop.

Select an option

Save nine1one/27457630cf223dea24c21b42c613e6e9 to your computer and use it in GitHub Desktop.
random.script.template

πŸš€ Installing GitHub Copilot in the CLI


🧰 Prerequisites

βœ… Access to GitHub Copilot

  • 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.

βœ… GitHub CLI Installed

  • 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.

⚠️ For Organization or Enterprise Users

  • 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.

πŸ› οΈ Installing Copilot in the CLI

βœ… Step 1: Authenticate (if not already logged in)

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

πŸ€– Step 2: Install the Copilot CLI Extension

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

πŸ”„ Step 3: Update the Copilot CLI Extension (Anytime)

If an update to the extension is available, use this command to upgrade it:

gh extension upgrade gh-copilot

πŸ“– Further Reading


🧠 Access and Installation Details

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.


πŸ€– Getting Command Explanations

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"

πŸ’‘ Getting Command Suggestions

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.


βš™οΈ Setting Up Aliases for Different Shells

🐚 Bash Setup

To set up aliases for Bash, add this to your .bashrc file:

echo 'eval "$(gh copilot alias -- bash)"' >> ~/.bashrc

πŸ’» PowerShell Setup

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

πŸ–₯️ Zsh Setup

To set up aliases for Zsh, add this to your .zshrc file:

echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc

βš™οΈ Changing the Default Execution Confirmation

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".


πŸ“Š Changing Usage Analytics

By default, Copilot sends anonymous usage data to GitHub to help improve the product. You can opt out of this data collection.

Example Usage Data:

{
   "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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment