2 min read

Supercharge your CLI with GitHub Copilot

If you spend a lot of time working with GitHub, it can be more efficient to manage your work from the command line. GitHub offers a tool called GitHub CLI, which you can install using either Homebrew or WinGet.

With the shortcut gh, you can manage your entire GitHub account directly in the terminal. You can work with gists, repositories, organizations, issues, and much more.

For example, if I want to create a private repository on GitHub, I can start with gh to see available commands, then add create option, and so on until I build the full command.

This works, but for one-time tasks it can be a bit tedious.

That’s where GitHub Copilot in the CLI comes in. It’s an extension you install directly in the terminal. You have to sign in with your GitHub account first and install the extension.

gh auth login
gh extension install github/gh-copilot

Sign in and install GC Copilot for CLI

Once installed, you get access to the gh copilot command, which provides two main features.

Suggest

The first feature is suggest, which generates a command or a set of commands based on your prompt. Let’s say:

I want to create a repository locally and then push it to GitHub as a private repository named Kangaroo.

All I need to do is run: gh copilot suggest "MY PROMPT"

Now I can choose from several options. I can prefer a specific tool, like gh or git, or go with a generic command. For scenarios like this, the generic option is usually best.

As you can see, Copilot suggests a full set of commands. What if I don’t understand some of them? That’s where the explain option helps. Copilot will generate explanations for each command.

If something doesn’t fit, I can refine it using revise command. Finally, I can either run the commands right away or copy them to my clipboard.

Explain

And what if you already have a command in front of you but don’t know what it does?

Just use explain and let Copilot break it down for you.

gh copilot explain "git commit -m Initial commit" 

Explain command

Now you know all the essentials about GitHub Copilot in the CLI. And here’s the best part: when designing commands, you don’t have to limit yourself to GitHub and Git. You can also try other commands... and it works perfectly.

Comments