Introduction to GitHub Copilot CLI Beginner

GitHub Copilot in the CLI brings AI-powered assistance directly to your terminal. Instead of writing code, it helps you find the right commands, understand complex shell syntax, and navigate unfamiliar tools — all using natural language.

What is GitHub Copilot CLI?

GitHub Copilot CLI is an extension for the GitHub CLI (gh) that provides AI-powered command-line assistance. It allows you to describe what you want to do in plain English, and it suggests the appropriate shell command, git command, or GitHub CLI command.

The extension is accessed through the gh copilot command and provides two primary capabilities:

💡

gh copilot suggest

Describe what you want to do, and Copilot suggests the exact command you need. Supports general shell commands, git commands, and GitHub CLI commands.

📚

gh copilot explain

Paste any command you do not understand, and Copilot breaks it down, explaining each part, flag, and argument in plain English.

How It Works

When you use gh copilot suggest or gh copilot explain, the following happens behind the scenes:

  1. You describe your intent — Type a natural language description of what you want to accomplish, or paste a command you want explained.
  2. The request is sent to GitHub's AI — Your query is sent to GitHub's Copilot AI service, which uses a large language model to understand your request.
  3. A command is generated or explained — The AI returns a suggested command (for suggest) or a detailed explanation (for explain).
  4. You review and optionally execute — You can review the suggestion, copy it to your clipboard, or run it directly in your terminal.
Terminal
# Ask Copilot to suggest a command
$ gh copilot suggest "find all files larger than 100MB"

# Copilot suggests:
# find . -type f -size +100M

# Options:
# ? Copy command to clipboard
# ? Execute command
# ? Revise command
# ? Rate response
# ? Exit

Key Capabilities

Command Suggestions

Copilot CLI can suggest commands across three categories:

Category Description Example Request
General Shell Unix/Linux shell commands, file operations, text processing, system administration "list all running processes sorted by memory usage"
Git Git version control commands for branching, committing, merging, rebasing, and more "undo the last commit but keep changes staged"
GitHub CLI GitHub CLI (gh) commands for repos, PRs, issues, actions, and more "list all open pull requests assigned to me"

Command Explanations

Ever encountered a cryptic command in a script or Stack Overflow answer? Copilot CLI can explain any command in detail:

Terminal
$ gh copilot explain "awk '{print $2}' file.txt | sort | uniq -c | sort -rn | head -10"

# Explanation:
# This command pipeline does the following:
# 1. awk '{print $2}' file.txt - Extracts the second column from file.txt
# 2. sort - Sorts the extracted values alphabetically
# 3. uniq -c - Counts consecutive duplicate lines
# 4. sort -rn - Sorts numerically in reverse (highest count first)
# 5. head -10 - Shows only the top 10 results

Error Explanations

When you encounter an error message in your terminal, you can ask Copilot to explain what went wrong and how to fix it:

Terminal
$ gh copilot explain "fatal: refusing to merge unrelated histories"

# Explanation:
# This Git error occurs when you try to merge or pull from a branch
# that has no common ancestor with your current branch.
# To resolve this, you can use:
#   git pull origin main --allow-unrelated-histories

How It Differs from GitHub Copilot Code Completion

GitHub Copilot has multiple products. It is important to understand how Copilot CLI fits into the broader ecosystem:

Feature Copilot Code Completion Copilot CLI
Where it works Inside your code editor (VS Code, JetBrains, etc.) In your terminal / command line
What it generates Code completions, functions, classes Shell commands, git commands, gh CLI commands
Trigger Automatic as you type code On demand via gh copilot suggest/explain
Context Your open files, imports, code structure Your natural language description
Use case Writing application code Finding and understanding terminal commands
Complementary Tools: Copilot Code Completion and Copilot CLI are designed to work together. Use code completion when writing code in your editor, and use the CLI when you need to run commands, manage git, or perform system operations.

Requirements

To use GitHub Copilot CLI, you need the following:

Prerequisites:
  • GitHub Copilot subscription — Individual, Business, or Enterprise plan
  • GitHub CLI (gh) — Version 2.40.0 or later
  • GitHub account — Authenticated via gh auth login
  • Internet connection — Copilot CLI requires connectivity to process requests
Subscription Required: Unlike some GitHub features, Copilot CLI requires an active Copilot subscription. Free GitHub accounts without Copilot access cannot use this extension. Check your subscription at github.com/settings/copilot.

Supported Platforms

Platform Support Notes
macOS Full support Works with Terminal, iTerm2, and other terminal emulators
Linux Full support Works with bash, zsh, fish, and other shells
Windows Full support Works with PowerShell, Command Prompt, Git Bash, and WSL

Try It Yourself

Before moving on to installation, verify your setup:

  1. Check if you have an active GitHub Copilot subscription at github.com/settings/copilot
  2. Check if GitHub CLI is installed: run gh --version in your terminal
  3. If not installed, proceed to the Installation lesson