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

Explains what a command does in natural language.

Example output:

2. gh copilot suggest

Generates shell commands from natural language descriptions.

Example output:

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

  1. Be Specific: The more detailed your description, the more accurate the suggestions.

  2. Learn from Explanations: Use the explain command to learn unfamiliar commands.

  3. Iterate on Suggestions: If the initial suggestion isn't quite right, refine your request.

  4. Combine with Traditional Tools: Use Copilot CLI alongside traditional command line tools like man, tldr, and --help.

  5. Review Before Executing: Always review suggested commands before running them, especially for destructive operations.

Security Considerations

  1. Command Review: Always review suggested commands before execution.

  2. Sensitive Information: Avoid including sensitive information in your requests.

  3. System Access: Remember that executed commands have the same permissions as your current user.

  4. Network Connectivity: All queries are sent to GitHub's servers, requiring internet connectivity.

Troubleshooting

Common Issues

  1. Authentication Problems

    • Run gh auth status to check GitHub CLI authentication

    • Try re-authenticating with gh auth login followed by gh copilot auth login

  2. Command Not Found

    • Ensure Node.js is installed and in your PATH

    • Verify installation with npm list -g @githubnext/github-copilot-cli

  3. Poor Suggestions

    • Be more specific in your requests

    • Try rephrasing the request

    • Ensure you're using English for best results

  4. API Rate Limits

    • If you encounter rate limits, wait before making more requests

    • Consider upgrading your GitHub plan for higher limits

Getting Help

Last updated