CLI Usage
This guide covers the GitHub Copilot Command Line Interface (CLI), a powerful tool that brings AI-assisted coding to your terminal.
Overview
GitHub Copilot CLI enhances your command line experience with:
Natural language explanations of shell commands
Command generation from natural language descriptions
Shell command transformations and improvements
Git operations assistance
Installation
Prerequisites
Node.js 16 or higher
npm or yarn
GitHub CLI (
gh
)GitHub Copilot subscription
Standard Installation
Verification
After installation, verify that the CLI works correctly:
You should receive an explanation of the command, which lists directories in the current location.
Core Commands
GitHub Copilot CLI offers three primary commands:
1. gh copilot explain
gh copilot explain
Explains what a command does in natural language.
Example output:
2. gh copilot suggest
gh copilot suggest
Generates shell commands from natural language descriptions.
Example output:
3. gh copilot what-the-shell
(or wts
)
gh copilot what-the-shell
(or wts
)Transforms one command into another based on your needs.
Example output:
Advanced Usage
Environment Variables
Customize Copilot CLI behavior with environment variables:
Creating Aliases
Set up aliases in your shell configuration file (~/.bashrc
, ~/.zshrc
, etc.):
Integration with Shell History
Use Copilot CLI to improve previous commands:
Real-World DevOps Scenarios
Scenario 1: Kubernetes Troubleshooting
Scenario 2: Complex Log Analysis
Scenario 3: Infrastructure Deployment
Tips for Effective Use
Be Specific: The more detailed your description, the more accurate the suggestions.
Learn from Explanations: Use the
explain
command to learn unfamiliar commands.Iterate on Suggestions: If the initial suggestion isn't quite right, refine your request.
Combine with Traditional Tools: Use Copilot CLI alongside traditional command line tools like
man
,tldr
, and--help
.Review Before Executing: Always review suggested commands before running them, especially for destructive operations.
Security Considerations
Command Review: Always review suggested commands before execution.
Sensitive Information: Avoid including sensitive information in your requests.
System Access: Remember that executed commands have the same permissions as your current user.
Network Connectivity: All queries are sent to GitHub's servers, requiring internet connectivity.
Troubleshooting
Common Issues
Authentication Problems
Run
gh auth status
to check GitHub CLI authenticationTry re-authenticating with
gh auth login
followed bygh copilot auth login
Command Not Found
Ensure Node.js is installed and in your PATH
Verify installation with
npm list -g @githubnext/github-copilot-cli
Poor Suggestions
Be more specific in your requests
Try rephrasing the request
Ensure you're using English for best results
API Rate Limits
If you encounter rate limits, wait before making more requests
Consider upgrading your GitHub plan for higher limits
Getting Help
Run
gh copilot --help
for command-line help
Last updated