Boost Your Terminal Productivity with GitHub Copilot CLI
The Copilot CLI acts as a productivity multiplier, mainly by assisting with tasks that involve the command line, which we use constantly for things like Git, file manipulation, and deploying applications.
Command Generation
Forget complex or rarely used command syntax. Just describe what you want to do in plain English, and Copilot will suggest the exact command. This is a massive time-saver for tasks like finding a specific file, manipulating permissions, or running complex Git operations.
Git Assistance
It simplifies tricky Git commands. Need to undo the last commit without losing the changes? Want to squash the last three commits? Just ask, and the CLI will provide the correct git command.
Command Explanation
Ever encounter a command online or in a script that looks like hieroglyphics? You can ask the CLI to explain any complex shell command, making it a fantastic learning tool.
Boilerplate & Scripting
It can help generate simple shell scripts or find the right command sequence for common automation tasks, speeding up your workflow when setting up environments or running builds.
IDE Agnostic
Since it's in the terminal, it works great regardless of your preferred Integrated Development Environment (IDE), ensuring a consistent AI-powered experience across your tools.
Before you start, you'll need a GitHub Copilot subscription and the GitHub CLI (gh) installed on your system.
You install the Copilot CLI as an extension to the main GitHub CLI utility. Open your terminal and run the following command
gh extension install github/copilot-cli
This command fetches the Copilot CLI extension and makes it available through your GitHub CLI.
After installation, you can verify it by typing the main command
gh copilot
The first time you use it, the CLI might prompt you to log in to GitHub if you haven't already, so it can verify your Copilot subscription.
The Copilot CLI offers two main ways to interact with it
| Command | Purpose |
gh copilot explain | Explains a command you give it. |
gh copilot suggest | Suggests a command based on a natural language prompt. |
?? (shorthand) | Alias for gh copilot suggest (if configured in your shell). |
git-copilot | Dedicated alias for Git-related suggestions. |
Here are some friendly, practical examples of how a software engineer would use the Copilot CLI in their daily work
Let's say you need to find all Python files in the current directory and its subdirectories that contain the word "TODO".
gh copilot suggest "find all python files recursively that contain the string TODO"
Copilot's Suggested Output
# Copilot suggests:
find . -name "*.py" -exec grep -l "TODO" {} \;
# Or with a simpler command:
grep -r --include "*.py" "TODO" .
(You can then choose which command to execute.)
You messed up a rebase and want to go back to the state before you started it.
git-copilot "how to abort the current rebase operation"
Copilot's Suggested Output
# Copilot suggests:
git rebase --abort
You encounter a command that uses awk and are unsure what it does.
gh copilot explain "cat file.txt | awk '{print \$2}' | sort | uniq -c"
Copilot's Explanation
This command first displays the content of 'file.txt' (cat file.txt).
Then, it pipes the content to 'awk' which prints the second column of each line (awk '{print $2}').
Next, the output is piped to 'sort' to arrange the lines alphabetically.
Finally, 'uniq -c' counts the occurrences of each unique line.
In short: It counts the frequency of the second word in each line of file.txt.
This is incredibly useful for debugging and understanding complex shell scripts or commands found online.
For maximum speed, many engineers set up a simple alias like ?? for gh copilot suggest.
# Set up the alias (you'd typically put this in your .bashrc or .zshrc)
alias ??='gh copilot suggest'
Now, you can just use ?? in the terminal
?? "create a compressed tar archive of the 'my-project' folder"
Copilot's Suggested Output
# Copilot suggests:
tar -czf my-project.tar.gz my-project
I hope this gives you a clear picture of how the Copilot CLI can significantly boost your terminal productivity!