Tips & Tricks Advanced

Become a power user of GitHub Copilot CLI. This lesson covers advanced tips, techniques for combining it with other tools, common patterns, known limitations, and answers to frequently asked questions.

Power User Tips

1. Be Specific with Context

The more context you provide, the better the suggestion. Include details like your OS, the tool you are using, and the specific outcome you want.

Terminal
# Vague - may give a generic answer
$ gh copilot suggest "compress files"

# Specific - gives a precise answer
$ gh copilot suggest "compress all .log files older than 7 days in /var/log into a single tar.gz archive on Ubuntu"

2. Use the Revise Feature Iteratively

When the first suggestion is not perfect, choose "Revise command" and add constraints rather than starting over.

Terminal
# First attempt
$ gh copilot suggest "find duplicate files"
# Suggestion: fdupes -r .

# Revise: "but without installing extra tools, use only built-in commands"
# Revised: find . -type f -exec md5sum {} + | sort | uniq -w32 -dD

# Revise again: "also exclude the .git directory"
# Revised: find . -type f -not -path './.git/*' -exec md5sum {} + | sort | uniq -w32 -dD

3. Learn from Explain

Use explain on commands you find in documentation, Stack Overflow, or scripts. Over time, this builds your command-line knowledge.

Learning Pattern: Whenever you encounter an unfamiliar command in a codebase, blog post, or tutorial, immediately run gh copilot explain "the command". This is faster than searching docs and gives you contextual understanding.

4. Chain Suggest and Explain

After getting a suggestion, use explain on it to make sure you understand every part before running it.

Terminal
# Step 1: Get a suggestion
$ gh copilot suggest "find all symlinks pointing to non-existent targets"
# Suggestion: find . -xtype l

# Step 2: Understand it
$ gh copilot explain "find . -xtype l"
# -xtype l matches symbolic links whose target does not exist (broken symlinks)

5. Use for Learning New Tools

When you start using a new CLI tool (e.g., kubectl, terraform, aws), Copilot CLI serves as an interactive cheat sheet.

Terminal
# Learning Terraform
$ gh copilot suggest "initialize a terraform project in current directory"
$ gh copilot suggest "show what terraform would change without applying"
$ gh copilot suggest "import an existing AWS S3 bucket into terraform state"

# Learning AWS CLI
$ gh copilot suggest "list all S3 buckets and their sizes"
$ gh copilot suggest "copy a local file to an S3 bucket with public read access"

Combining with Other CLI Tools

Copilot CLI works best when combined with your existing workflow and tools.

With Shell History

~/.bashrc
# Function: explain the last command you ran
explain_last() {
  local last=$(fc -ln -1 | sed 's/^\s*//')
  echo "Explaining: $last"
  gh copilot explain "$last"
}
alias why='explain_last'

# Usage:
# $ find . -name '*.tmp' -mtime +7 -delete
# $ why
# → Explains the find command you just ran

With fzf (Fuzzy Finder)

~/.bashrc
# Browse and explain commands from your history
explain_history() {
  local cmd=$(history | fzf --tac | sed 's/^ *[0-9]* *//')
  if [ -n "$cmd" ]; then
    gh copilot explain "$cmd"
  fi
}
alias eh='explain_history'

With tldr and man

Terminal
# Use tldr for quick reference, Copilot for specific tasks
$ tldr tar                  # Quick overview of tar
$ gh copilot suggest "extract a tar.bz2 file to a specific directory"  # Specific task
$ man tar                  # Full manual for deep understanding

Common Patterns

These are frequently useful patterns that leverage Copilot CLI effectively.

The "How do I..." Pattern

Terminal
# Start your queries with the task you want to accomplish
$ gh copilot suggest "monitor CPU usage in real time"
$ gh copilot suggest "recursively change file ownership to current user"
$ gh copilot suggest "compare two directories for differences"

The "Convert from X to Y" Pattern

Terminal
# Converting between formats
$ gh copilot suggest "convert a CSV file to JSON using command line"
$ gh copilot suggest "convert all PNG images in a directory to JPEG"
$ gh copilot suggest "convert a YAML file to JSON"

The "Platform-Specific" Pattern

Terminal
# Include your platform for accurate suggestions
$ gh copilot suggest "check which process is using port 3000 on macOS"
$ gh copilot suggest "install Node.js 20 on Ubuntu 22.04"
$ gh copilot suggest "set an environment variable permanently on Windows PowerShell"

Limitations to Know

Copilot CLI is a powerful tool, but it has limitations you should be aware of:

Limitation Details Workaround
No file context Copilot CLI does not read your files or directory structure Include relevant details in your query (file names, paths, formats)
Internet required Requires an active internet connection for every request Cannot be used offline; consider saving common commands in notes
May suggest incorrect commands AI can hallucinate flags, options, or command syntax Always review before executing; use --help to verify flags
No persistent memory Each suggestion is independent; no conversation history Include full context in each query
Subscription required Requires an active GitHub Copilot subscription No free tier available; check with your organization
Rate limits May have rate limits on the number of suggestions per minute If rate-limited, wait a moment and try again
Always Verify: Never blindly execute a suggested command, especially on production systems. Copilot CLI is an assistant, not an authority. It can suggest commands with incorrect flags, wrong syntax for your specific OS version, or commands that are destructive. Verify with --help, man pages, or official documentation.

Frequently Asked Questions

No. GitHub Copilot CLI requires an active GitHub Copilot subscription. This can be an Individual plan ($10/month or $100/year), a Business plan ($19/user/month), or an Enterprise plan ($39/user/month). Some students and open-source maintainers may qualify for free access through GitHub Education or the GitHub Copilot for Open Source program.

No. Unlike GitHub Copilot code completion in your editor, Copilot CLI does not read your files, directory contents, or source code. It only processes the natural language description you provide and your shell/OS environment type. Your code remains entirely on your local machine.

Yes. Copilot CLI works with GitHub Enterprise Cloud and GitHub Enterprise Server. Set the GH_HOST environment variable to your Enterprise hostname, and authenticate with gh auth login --hostname your-enterprise.com. Your organization admin must have Copilot enabled for your account.

Copilot CLI is purpose-built for command-line usage. Key differences: (1) It is integrated directly into your terminal workflow via gh, so there is no need to switch to a browser. (2) It detects your shell environment automatically. (3) It offers direct execute/copy/revise options. (4) It is specifically tuned for shell, git, and GitHub CLI commands. General AI assistants like ChatGPT or Claude can also help with commands but require more context switching.

No. Copilot CLI requires an active internet connection for every suggestion and explanation. The AI model runs on GitHub's servers, not locally. If you are in an environment without internet access, consider saving commonly needed commands in a local cheat sheet file or using offline tools like tldr or cheat.

While technically possible, Copilot CLI is designed for interactive use. It relies on an interactive terminal for choosing options (execute, revise, copy). In CI/CD, you should use specific, tested commands rather than AI-generated suggestions. Copilot CLI is best used during development to discover commands that you then hard-code into your pipeline scripts.

Copilot CLI generates commands for all major operating systems (macOS, Linux, Windows) and shells (bash, zsh, fish, PowerShell, Command Prompt). Queries and explanations are primarily in English, though it can understand queries in other languages to some degree. The tool itself runs on any platform that supports GitHub CLI.

Course Complete!

Congratulations on completing the GitHub Copilot CLI course. Here are some next steps:

  1. Set up your aliases and shell functions from the Configuration lesson
  2. Make Copilot CLI part of your daily workflow for at least a week
  3. Keep a log of the most useful commands it suggests for your reference
  4. Explore the GitHub Copilot course to learn about code completion in your editor
  5. Check out the Copilot Chat course for conversational AI in your IDE