Skip to content
The Lazy Administrator
  • Home
  • Disclaimer
  • Contact
  • About Me
  • Search Icon

The Lazy Administrator

Finding ways to do the most work with the least effort possible

Getting Started with GitHub Copilot in the CLI

Getting Started with GitHub Copilot in the CLI

March 22, 2024 Brad Wyatt Comments 1 comment

Table of Contents

  • Install the GitHub CLI
    • Windows
      • Winget
    • MacOS
      • Homebrew
  • Authenticate
  • GitHub CLI Commands
  • Install the Copilot CLI Extension
  • Available Commands
    • Alias
      • Zsh
      • PowerShell
    • Explain a Command
    • Suggest a Command
      • Suggest Actions

It was announced recently that GitHub Copilot in the CLI has reached General Availablity for all Individual, Business, and Enterprise customers. In this post, I will show you how you can get download and install the CLI and Copilot extension, authenticate to use Copilot, and the available commands and use cases.

Install the GitHub CLI

Windows

With Windows, we can install the GitHub CLI via the command line (Winget, Chocolatey, or Scoop) or manually from here.

Winget

With Winget, we can install the GitHub CLI using the following command:

winget install --id GitHub.cli

MacOS

With MacOS, we can install the GitHub CLI via homebrew or manually from here.

Homebrew

Using homebrew, run the following command:

brew install gh

Authenticate

Note: In order to use Copilot in the CLI, you must have an active GitHub Copilot subscription.

Once you have a valid subscription to use Copilot, run the following command to authenticate:

gh auth login

Select the type of account you want to log into. In my case, Github Copilot is associated with my Github.com account, so I will select that option using the arrow keys.

Next, it will ask you your preferred protocol to authenticate. In my example, I will use HTTPS.

Next, it will ask if you want to authenticate Git with your GitHub Credentials. Enter “Y” to confirm. Then you can authenticate using a web browser or paste an auth token directly into the terminal.

Using the web, you will authenticate using device code flow. It will show you a code in your terminal and if you press “Enter” it will open a web browser to https://github.com/login/device

Enter the code that you were shown in your terminal and press, “Continue.”

Review and approve the requested permissions.

GitHub CLI Commands

The GitHub CLI has a manual that contains all the available commands. The manual can be found here.

Install the Copilot CLI Extension

Now that we have the GitHub CLI installed and authenticated, we need to install the GitHub Copilot Extension. To install the extension, use the following command:

gh extension install github/gh-copilot

Available Commands

The built-in help can assist you with understanding how you can interact with the Copilot CLI extension. You can run the help by running the following command:

gh copilot --help

Alias

An alias is another name you can use to call the Copilot CLI, and it can be used interchangeably. Using gh copilot alias, we can create different aliases. You can also create an alias around longer commands, such as replacing gh copilot suggest with ghcs or replacing gh copilot explain with ghce.

To get help for the Alias commands, let’s run the following command:

gh copilot alias --help

From there, we can see the different alias commands for the different shells. You can copy and paste the code, but I will go into futher details below.

Zsh

If you are running Zsh, run the following commands to create the aliases:

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

Note: Since I am running iTerm I will add the source command, ‘source ~/.zshrc; clear‘ to my startup prompt.

Now, I can run ghce for gh copilot explain or ghcs instead of gh copilot suggest.

PowerShell

Note: Since I am on a Mac running pwsh, I had to first add the gh binary to my path. To do this, I ran, “sudo nano /etc/paths.d/gh” and then entered, “/Users/MYUSERNAME/homebrew/bin/“. Be aware that your binary may be in a different directory. Since I installed it via Homebrew, it is located at the path above. If you run ‘where gh‘ in the terminal, it will tell you the CLI’s path.

For PowerShell, you need to run the following 3 lines to add the aliases:

$GH_COPILOT_PROFILE = Join-Path -Path $(Split-Path -Path $PROFILE -Parent) -ChildPath "gh-copilot.ps1"
gh copilot alias -- pwsh | Out-File ( New-Item -Path $GH_COPILOT_PROFILE -Force )
echo ". $GH_COPILOT_PROFILE" >> $PROFILE

This adds a script to the root of your profile path and adds the following line to your $PROFILE:

. /Users/YOURUSERNAME/.config/powershell/gh-copilot.ps1

Now, in PowerShell, I can use the aliases. In my example, I am asking for it to suggest (ghcs) a PowerShell command to get today’s date as a string.

Explain a Command

Github Copilot has the ability to explain commands to you within the shell. Using my alias of ghce (gh copilot explain). If you put the language prior to the command, it will tell you information about that language’s command. In my example below, I will show the following examples:

  1. Get-Date command for PowerShell
  2. Pip command for Python

You can also just run ghce 'powershell get-date' instead of just ghce and then going through the prompts.

You can also run the following command to view the Explain help and see more real-world examples:

gh copilot explain --help

Suggest a Command

Copilot CLI can also suggest a command using natural language. In my example below, I want to find the command to get today’s date:

ghcs "get todays date in powershell"

You can also just run ghcs or gh copilot suggest and it will prompt you

Suggest Actions

You may have noticed that after you have copilot suggest a command, there are several available options presented to you:

  1. Copy Command to Clipboard: Copies the suggested command straight to your clipboard
  2. Explain command: Uses gh copilot explain against the suggested command
  3. Execute command: Execute the suggested command in your terminal.
  4. Revise command: Prompts you on how you want to revise the suggested command and then runs that through gh copilot suggest. (In the example below, I was suggested Get-Date -Format "yyyy-MM-dd" and I suggested it not to format the date string)
  5. Rate response: rate the suggested command
  6. Exit: Exits the copilot actions menu.
Brad Wyatt
Brad Wyatt

My name is Bradley Wyatt; I am a 5x Microsoft Most Valuable Professional (MVP) in Microsoft Azure and Microsoft 365. I have given talks at many different conferences, user groups, and companies throughout the United States, ranging from PowerShell to DevOps Security best practices, and I am the 2022 North American Outstanding Contribution to the Microsoft Community winner.


AI
CLI, Copilot, GitHub, PowerShell, Zsh

Post navigation

PREVIOUS
View and Export your Intune Device Management Scripts Using the Microsoft Graph PowerShell SDK
NEXT
Upload a file to Connectwise and Attach it to a Service Ticket with PowerShell

One thought on “Getting Started with GitHub Copilot in the CLI”

  1. Kristopher Gates says:
    May 9, 2025 at 9:20 am

    I appreciate this clean, linear guide to configuring GitHub Copilot in PowerShell. It’s fun to have and this was a motivating guide to follow in installing and first usages of it.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe

Email


Categories

  • Active Directory (8)
  • AI (3)
  • API (1)
  • AutoPilot (2)
  • Azure (15)
  • Bicep (4)
  • Connectwise (1)
  • Defender for Cloud Apps (1)
  • Delegated Admin (1)
  • DevOps (6)
  • Graph (6)
  • Intune (15)
  • LabTech (1)
  • Microsoft Teams (6)
  • Office 365 (19)
  • Permissions (2)
  • PowerShell (50)
  • Security (1)
  • SharePoint (3)
  • Skype for Business (1)
  • Terraform (1)
  • Uncategorized (2)
  • Yammer (1)

Recent Comments

  • Mike D on Upload a file to Connectwise and Attach it to a Service Ticket with PowerShell
  • Side Eye on Homeland Security’s Trusted Travelers API and PowerShell – Getting a Better Global Entry Interview Using PowerShell
  • Lisa on Allow Non-Admin Users to Manage Their Desktop Icons Using Intune
  • A1 Lottery LOGIN on Get a New Computer’s Auto Pilot Hash Without Going Through the Out of Box Experience (OOBE)
  • Kristopher Gates on Getting Started with GitHub Copilot in the CLI

1,752,786 People Reached

© 2025   All Rights Reserved.