Introduction to Copilot CLI
5 minutes
GitHub Copilot CLI brings AI-powered assistance directly to your terminal. Instead of switching to a browser to look up a command or its flags, you can ask Copilot in plain language — right where you are working.
What is Copilot CLI?
Copilot CLI is a GitHub CLI extension that lets you interact with GitHub Copilot from your terminal. It provides two primary sub-commands:
gh copilot suggest— Translate a natural-language task description into a shell commandgh copilot explain— Get a plain-language explanation of any shell command
Why Does It Matter?
Developers spend a significant portion of their time in the terminal. Copilot CLI integrates AI assistance directly into that workflow so you can:
- Avoid context-switching to search engines or documentation sites
- Quickly recall syntax for commands you use infrequently
- Understand unfamiliar commands before running them
- Discover more efficient ways to accomplish common tasks
- Learn new tools and options without leaving the terminal
Learning Objectives
By the end of this workshop activity you will be able to:
- Install and authenticate the GitHub Copilot CLI extension
- Use
gh copilot suggestto get shell command suggestions from natural language - Use
gh copilot explainto understand unfamiliar commands - Set up shell aliases (
ghcsandghce) for faster access - Integrate Copilot CLI into everyday terminal workflows
Prerequisites
- GitHub CLI (
gh) v2.x or later installed and authenticated — Install from cli.github.com - A GitHub Copilot license — Individual, Business, or Enterprise. Learn more about plans
- A supported shell — Bash, Zsh, Fish, or PowerShell
Verify that gh is installed and authenticated by running:
gh auth status
You should see a confirmation that you are logged in to github.com.
Exercise 1: Install Copilot CLI
5 minutes
Copilot CLI is distributed as a GitHub CLI extension. Extensions are installed with a single command and kept up to date with gh extension upgrade.
Install the Extension
Run the following command to install the GitHub Copilot CLI extension:
gh extension install github/gh-copilot
Verify the Installation
Confirm the extension is installed and check which version is active:
gh copilot --version
You should see output similar to:
gh-copilot version 1.x.x (yyyy-mm-dd)
View Available Commands
Explore what Copilot CLI can do:
gh copilot --help
Update the extension at any time with:
gh extension upgrade gh-copilot
Authenticate (if prompted)
On first use, Copilot CLI may prompt you to grant additional permissions. Follow the on-screen instructions to complete the OAuth flow in your browser. After authentication, return to your terminal — you are ready to start using Copilot CLI.
Exercise 2: Suggest Commands
10 minutes
gh copilot suggest converts a plain-language description into a shell command. You describe what you want to accomplish, and Copilot returns a command you can copy, run, or refine.
Basic Usage
gh copilot suggest "<describe the task in plain English>"
Choosing a Shell Target
You can tell Copilot which shell environment you are targeting with the --target flag:
gh copilot suggest --target shell "list all files modified in the last 7 days"
gh copilot suggest --target git "show a compact commit log for the last 10 commits"
gh copilot suggest --target gh "list open pull requests in the current repo"
Supported targets are shell, git, and gh. When omitted, Copilot infers the best target from your description.
Interactive Response
After Copilot suggests a command, it presents an interactive menu:
- Copy command to clipboard — Paste it into your terminal manually
- Explain command — Get a plain-language explanation before running it
- Execute command — Run the command immediately in your current shell
- Revise command — Provide additional context to refine the suggestion
Hands-on Exercises
- Ask Copilot to suggest a command to list all files modified in the last 7 days:
gh copilot suggest "list all files modified in the last 7 days" - Ask for a command to find all files larger than 100 MB in your home directory:
gh copilot suggest "find all files larger than 100MB in my home directory" - Use the
--target gitflag to ask for a Git command:gh copilot suggest --target git "show a compact graph of the last 10 commits across all branches" - Try the interactive Revise command option to add more specificity to one of the suggestions
The more specific your description, the more accurate the suggestion. Include details like file types, time ranges, or output formats to get better results.
Exercise 3: Explain Commands
10 minutes
gh copilot explain takes any shell command and returns a clear, plain-language explanation of what it does — including each flag and argument. This is invaluable when you encounter unfamiliar commands in scripts, documentation, or Stack Overflow answers.
Basic Usage
gh copilot explain "<command to explain>"
Hands-on Exercises
- Explain an interactive Git rebase:
gh copilot explain "git rebase -i HEAD~3" - Explain a complex
findcommand:gh copilot explain "find . -type f -name '*.log' -mtime +30 -delete" - Explain a
pspipeline:gh copilot explain "ps aux | grep node | awk '{print $2}' | xargs kill" - Paste a command from a script you are unfamiliar with and ask Copilot to explain it
Always use gh copilot explain before running an unfamiliar command with elevated privileges (sudo) or destructive flags (-rf, --force, --delete). Understanding a command before running it is a healthy habit.
Piping Output to Explain
You can pipe command output directly to Copilot explain for contextual help:
cat error.log | gh copilot explain
This is useful for understanding error messages or log output without copying and pasting manually.
Exercise 4: Shell Alias Setup
10 minutes
Typing gh copilot suggest or gh copilot explain every time is verbose. Setting up short shell aliases — ghcs (GitHub Copilot Suggest) and ghce (GitHub Copilot Explain) — makes Copilot CLI feel like a natural part of your workflow.
Automatic Alias Setup
Copilot CLI can generate the alias configuration for your shell automatically:
gh copilot alias -- bash
Replace bash with your shell (zsh, fish, or powershell). The command prints shell-specific configuration to standard output.
Bash / Zsh
Add the aliases to your shell configuration file:
# Add to ~/.bashrc or ~/.zshrc
eval "$(gh copilot alias -- bash)"
For Zsh, replace bash with zsh:
# Add to ~/.zshrc
eval "$(gh copilot alias -- zsh)"
After editing the file, reload your shell configuration:
source ~/.bashrc # or ~/.zshrc
Fish Shell
For Fish, add the configuration to your Fish config file:
# Run once to add to your Fish config
gh copilot alias -- fish | source
To make it permanent, add the following line to ~/.config/fish/config.fish:
gh copilot alias -- fish | source
PowerShell
For PowerShell on Windows, add the following to your PowerShell profile ($PROFILE):
Invoke-Expression (gh copilot alias -- powershell | Out-String)
Verify the Aliases Work
Open a new terminal session (or reload your shell config) and test the aliases:
ghcs "list all running Docker containers"
ghce "docker ps -a --format 'table {{.Names}}\t{{.Status}}'"
ghcs is a shorthand for gh copilot suggest and ghce is a shorthand for gh copilot explain. They accept exactly the same arguments as the full commands.
Challenge: Real-World Tasks
15 minutes
Now it is time to put everything together. Complete all three tasks below using only Copilot CLI suggestions — no manual searches or documentation. For each task, use ghcs (or gh copilot suggest) to generate the command, then use ghce (or gh copilot explain) to verify you understand what it does before running it.
Task 1: Repository Hygiene
Use Copilot CLI to find and remove all .DS_Store files from a Git repository (without deleting the files from disk, only from Git tracking).
- Hint: You will need a
gitcommand and a follow-up shell command - Use
ghcs --target gitfor the Git-specific part
ghcs --target git "remove all .DS_Store files from git tracking without deleting them from disk"
Task 2: Log Analysis
Your application generates log files in /var/log/app/. Use Copilot CLI to:
- Count the number of
ERRORlines across all.logfiles in that directory - Extract the 10 most recent unique error messages, sorted by frequency
- Use
ghcsfor each sub-task separately - Use
ghceto understand the pipeline before running it
Task 3: Docker Cleanup
Use Copilot CLI to generate commands that:
- List all Docker containers that exited more than 24 hours ago
- Remove all stopped containers, unused networks, dangling images, and build cache in a single command
- Always use
ghceto review destructive commands before executing them
Reflection
After completing the three tasks, consider:
- How did using Copilot CLI compare to your usual workflow for looking up commands?
- Which task benefited most from the
--targetflag? - Did any suggestion require refinement? What additional context helped?
Tips & Best Practices
5 minutes
Make the most of GitHub Copilot CLI with these tips and best practices gathered from real-world use.
Writing Effective Prompts
- Be specific — Include file types, time ranges, and output format in your description. "list log files" is less effective than "list all .log files in /var/log modified in the last 24 hours, sorted by size"
- Mention the tool or ecosystem — Saying "a git command to …" or "a Docker command to …" helps Copilot choose the right tool
- Use the
--targetflag — Setting--target gitor--target ghscopes suggestions and makes them more accurate - Iterate with "Revise" — The first suggestion may not be exactly what you need. Use the interactive Revise option to add constraints or change the approach
Safety and Verification
- Always explain before running — Particularly for destructive commands (
rm -rf,docker system prune, database drops). Useghceto review what a command does before executing it - Prefer dry-run flags — Many tools support
--dry-runor-nflags. Ask Copilot to include them: "list the files that would be deleted, without actually deleting them" - Review multi-piped commands carefully — Long pipelines can have unintended side effects. Break them into stages if you are unsure
Integrating Into Your Workflow
- Pair with your shell history — After Copilot suggests a command and you run it successfully, it is added to your shell history for easy recall with the up arrow
- Use it for learning — Ask Copilot to suggest a command you already know, then use explain to see if there is a more efficient variant you were not aware of
- Combine with scripts — Use Copilot CLI interactively to prototype shell scripts, then copy the final commands into a
.shfile - Use the aliases — Once you have set up
ghcsandghce, using Copilot CLI becomes as natural as running any other command
Useful Reference Commands
# Install / update
gh extension install github/gh-copilot
gh extension upgrade gh-copilot
# Suggest a shell command
gh copilot suggest "your task description"
ghcs "your task description" # with alias
# Suggest with explicit target
gh copilot suggest --target git "your task"
gh copilot suggest --target gh "your task"
# Explain a command
gh copilot explain "command to explain"
ghce "command to explain" # with alias
# Set up aliases (bash/zsh/fish/powershell)
eval "$(gh copilot alias -- bash)"
Additional Resources
- GitHub Copilot CLI Reference Manual
- Using GitHub Copilot in the command line
- GitHub CLI — cli.github.com
- gh-copilot extension on GitHub
🎉 Congratulations!
You have completed the Copilot CLI workshop activity! You can now:
- Install and authenticate the GitHub Copilot CLI extension
- Use
gh copilot suggestto get AI-powered shell command suggestions - Use
gh copilot explainto understand unfamiliar commands - Use short aliases (
ghcs/ghce) for faster access - Apply Copilot CLI to real-world terminal tasks safely and effectively
Next Steps
Continue your Path 3 journey by exploring the other extended capabilities:
- Copilot SDK — Build your own Copilot extensions
- Agent Skills — Define reusable Copilot behaviors
- Sub-Agents — Coordinate multi-agent workflows
- Copilot Memory — Persist context across conversations