MervCodes

Tech Reviews From A Programmer

GitHub Copilot in the CLI: Setup and Productivity Tips

1 min read

GitHub Copilot in the CLI: Setup and Productivity Tips

Most developers know GitHub Copilot as the autocomplete ghost text inside their editor. Fewer have discovered that Copilot also lives in the terminal, where it can explain cryptic commands, suggest the exact incantation you half-remember, and turn a plain-English request into a runnable shell command. If you spend a meaningful part of your day in a terminal—and most engineers do—bringing Copilot into that workflow removes a surprising amount of friction.

This guide walks through installing Copilot in the CLI, configuring it sensibly, and building habits that actually make you faster rather than just novelty features you try once and forget.

Why Use Copilot in the Terminal at All?

The terminal is where you feel the cost of forgotten syntax most sharply. Nobody remembers every tar flag, the precise ffmpeg invocation to convert a video, or how to find and kill the process holding port 3000. Traditionally you'd alt-tab to a browser, search, skim a Stack Overflow answer, and copy-paste. Copilot collapses that loop into a single prompt without leaving your prompt line.

It shines in three situations:

  • Command suggestion — you describe intent, Copilot proposes the command.
  • Command explanation — you paste a scary command, Copilot breaks it down.
  • Git and gh workflows — because it's GitHub's tool, it's especially strong at git operations and gh CLI usage.

Prerequisites

Before installing anything, make sure you have:

  • An active GitHub Copilot subscription (Individual, Business, or Enterprise). The CLI experience is included with your Copilot seat.
  • The GitHub CLI (gh) installed and authenticated, or a recent version of the standalone Copilot CLI.
  • A supported shell: bash, zsh, fish, or PowerShell.

Check your gh version first:

gh --version

If it's older than a year or two, update it through your package manager (brew upgrade gh, apt, winget, etc.) so the extension mechanism works cleanly.

Setup: Installing the Extension

The most common path is installing Copilot as a gh extension. Authenticate gh if you haven't:

gh auth login

Then install the Copilot extension:

gh extension install github/gh-copilot

Verify it loaded correctly:

gh copilot --version

You now have two primary subcommands available:

gh copilot suggest "find all files larger than 100MB"
gh copilot explain "grep -rInw . -e 'TODO'"

suggest turns intent into a command. explain turns a command into a plain-English breakdown. That's the whole core of the tool, and it's deceptively powerful once you make it reflexive.

Configuring Aliases for Speed

Typing gh copilot suggest in full defeats the purpose. Copilot ships an alias helper that wires short commands into your shell. Generate the aliases for your shell and source them:

# For bash
echo 'eval "$(gh copilot alias -- bash)"' >> ~/.bashrc

# For zsh
echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc

# For fish
gh copilot alias -- fish >> ~/.config/fish/config.fish

Reload your shell (source ~/.zshrc or open a new terminal). You'll now have two tiny aliases:

  • ghcs — Copilot suggest
  • ghce — Copilot explain

The magic of ghcs is that after Copilot proposes a command, it offers to execute it directly, copy it to your clipboard, or revise it. That execute step is what makes it feel native—you never manually copy-paste the result.

ghcs "compress this folder into a tar.gz named backup"

Everyday Productivity Patterns

1. Stop Googling One-Off Commands

The single biggest win is replacing web searches for command syntax. Instead of searching "how to recursively change file permissions," ask:

ghcs "recursively set all directories to 755 and files to 644 under ./public"

Review the output before running it—this is important—and hit execute.

2. Explain Before You Run

When a teammate, a README, or an AI pastes a dense command into your lap, don't run it blind. Pipe it through explain:

ghce "curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | sudo bash"

This is both a learning tool and a safety check. Understanding a command that pipes a remote script into sudo bash before executing it is exactly the habit that prevents bad days.

3. Lean on It for Git and gh

Copilot is unusually good at git because it's a GitHub product. Try:

ghcs "undo my last commit but keep the changes staged"
ghcs "list all branches merged into main that I can safely delete"
ghcs "create a draft PR from the current branch with a title and body"

The last one will often propose a full gh pr create command, tying the whole ecosystem together.

4. Target the Command Type

You can hint the kind of answer you want. Copilot's suggest supports a type flag for shell, git, or gh commands:

ghcs -t git "squash the last three commits into one"
ghcs -t gh "view the checks status on my current PR"

Constraining the domain tends to produce tighter, more accurate suggestions.

5. Chain Revisions Instead of Restarting

When a suggestion is close but not right, use the Revise option in the interactive menu rather than starting over. Tell it "use fd instead of find" or "add a dry-run flag" and it adjusts in place. Treat it as a short conversation, not a one-shot oracle.

Safety Habits That Matter

AI-generated shell commands are convenient and occasionally wrong. Build these guardrails into your muscle memory:

  • Always read before executing, especially anything with rm, sudo, dd, mv, force flags, or output redirection that overwrites files.
  • Prefer dry-run flags when they exist. Ask Copilot to include --dry-run or -n so you can preview effects.
  • Never pipe untrusted remote scripts into a shell just because Copilot suggested it. Inspect the script first.
  • Watch for destructive globs. A command that looks fine can match far more than you intend. When in doubt, echo or ls the glob before acting on it.

Copilot lowers the cost of trying commands, which is great—but that same speed makes a careless mistake faster too. The read-before-run discipline is non-negotiable.

Fitting It Into Your Real Workflow

The developers who get the most from CLI Copilot don't treat it as a separate mode—they blend it in. A practical rhythm looks like this:

  1. You hit a task you could do but would have to look up.
  2. Instead of context-switching to a browser, you fire ghcs "...".
  3. You skim the suggestion, revise if needed, and execute.
  4. When you learn a command well enough, you stop asking and just type it.

Over time Copilot becomes a fallback for the long tail of commands you use rarely, freeing your memory for the ones you use daily. It's also a genuinely good teacher: reading its explanations builds real fluency instead of copy-paste dependence.

Consider pairing it with your own shell aliases and functions. Copilot is best for the unpredictable, one-off needs; your dotfiles are best for the repetitive ones. Let each handle what it's good at.

FAQ

Do I need a paid Copilot subscription to use it in the CLI? Yes. The CLI experience is part of your GitHub Copilot seat—Individual, Business, or Enterprise. There's no separate purchase, but you do need an active subscription.

Does Copilot execute commands automatically without my approval? No. Suggestions are always presented for you to review first. You explicitly choose to execute, copy, revise, or cancel. Nothing runs until you say so.

Which shells are supported? bash, zsh, fish, and PowerShell all work, and the alias helper can generate the right integration for each.

Is my terminal input sent to GitHub's servers? Yes—your prompts are processed by Copilot's backend to generate suggestions, the same as the editor experience. Avoid pasting secrets, credentials, or sensitive proprietary data into prompts, and review your organization's Copilot data and privacy settings if you're on a Business or Enterprise plan.

How is this different from Copilot in my editor? The editor version completes code inline as you write. The CLI version is conversational and command-focused: you describe what you want a shell command to do, or ask it to explain one. Different context, different strengths.

What if the suggested command is wrong or dangerous? Use the Revise option to refine it, or simply cancel. Always read commands before executing—treat Copilot as a knowledgeable assistant, not an infallible authority, particularly for anything destructive.

Can it help with tools beyond git, like Docker or Kubernetes? Yes. While it's especially strong on git and gh, it handles general shell tooling—Docker, kubectl, ffmpeg, tar, find, and more—because those are common terminal tasks it's been trained on.

Wrapping Up

GitHub Copilot in the CLI won't replace understanding your tools, and it shouldn't. What it does well is eliminate the constant micro-friction of forgotten flags and half-remembered syntax, keeping you in the terminal and in flow. Install the extension, set up the ghcs and ghce aliases, build the habit of reading before running, and let it handle the long tail of commands you'd otherwise go looking up. Within a week it stops feeling like a gimmick and starts feeling like part of your shell.

Sources

Related Articles