TroubleChute Logo
CLI

GitHub Copilot CLI (Windows, Linux & Mac Install)


Published: Mar 7, 2024
Last Edit: Mar 8, 2024
AI CLI GitHub
1,343 Words, 6 Minutes.

Watch the video:


Timestamps:
0:00 - Intro
0:30 - What is the GitHub Copilot CLI
1:25 - Requirements
1:47 - Install gh
2:20 - Sign into gh & Enable Copilot CLI
3:00 - Testing GitHub Copilot CLI Explain & Suggest
3:54 - Installing GitHub Copilot CLI commands for Windows
5:36 - Creating Aliases in Windows PowerShell
6:28 - Using GitHub Copilot CLI on Windows

What is this

The GitHub Copilot is coming to the command line in the form of GitHub Copilot CLI. When you’re confused about what commands do or need help with crafting complicated CLI wizardry: This is where GitHub Copilot CLI comes in.

The GitHub CLI will exit technical preview on March 21st, 2024 and will become generally available in the coming weeks. You can read about this on the GitHub Next page

Currently, if you have a GitHub Copilot subscription as an indivitual or through a company or organization you should have access. I do at least.

What’s required

Besides a subscription, you need gh installed. This is the GitHub CLI. The steps are simple.

gh on Windows

The installation is simple. Download the msi installer file from the GitHub CLI page. Run it, and follow through with installation steps.

When it’s complete you should be able to run gh in a fresh CMD, Terminal or PowerShell window and see a response.

Alternatively you could use a package manager like WinGet, scoop and Chocolatey. Find instructions here on GitHub

gh on Linux and Mac

There installation steps for Linux and Mac mainly revolve around using your package manager.

If you’re on Mac you’ll use Homebrew, MacPorts, Conda, Spack or Webi, all listed on the GitHub page.

If you’re on Linux, as there are so many different ways, there is a dedicated install_linux.md file on the GitHub.

For example on Arch you can use pacman with sudo pacman -S github-cli

For Ubuntu:

Bash
1
2
3
4
5
sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

And so on.

Installing the gh copilot extension

The GitHub Copilot in its current state uses the previous gh program and runs as an extension. You will need to install it by following the commands on the Use GitHub Copilot in the CLI page

The first command below will log in, and the rest will install and update the gh-copilot extension. The gh auth login process is interactive and will require you to step in.

1
2
3
gh auth login
gh extension install github/gh-copilot
gh extension upgrade gh-copilot

Run the update command once in a while to make sure it is up-to-date.

Testing gh copilot

The gh copilot command is now installed, and you should be able to interact with it by running a few commands. The examples on the above page include:

1
2
3
4
gh copilot explain
gh copilot explain "sudo apt-get"
gh copilot suggest
gh copilot suggest "Install git"

Explain tells you what a command does, and suggest tells you how to structure a command for something you’re thinking about. Simple. Usually you may outsource this work on ChatGPT, Gemini or something else. Now, it’s in your terminal!

But this isn’t it. We can make it even better, and start using the advertised ??, git? and gh? commands. For this we need Node and a package.


Installing Node

You will need Node.js installed to use the GitHub Copilot shorter commands. This, again, differs based on your system.

Install Node.js on Windows

You can use a package manager like scoop or Chocolatey, but for users without a package manager, you’ll likely want to do it the old fashioned way.

Head to the Node.js Download page and download the latest Windows installer.

Run it, and once you’ve followed through with all the instructions you should be able to start a new terminal and run node --version as as well as npm to see a response.

Install Node.js on Linux or Mac

Mac has an installer similar to the Windows installer, which you can find on the Node.js Download page.

If you’re a Linux user I’d reccommend using a package manager. On Mac you could also use Homebrew or MacPorts to accomplish something similar.

You can find all the packaage manager installation commandsfor the many distros on the Installing Node.js via package manager page.

This includes macOS, Windows, as well as many Linux distros.

For example, Alpine users will run apk add nodejs npm. Arch users: pacman -S nodejs npm

Ubuntu users this time will need to use a distribution, or install it using Snap from the Snap store.


Install GitHub Copilot npm package

Now that Node.js is installed, we can proceed to installing the GitHub Copilot package to allow the usage of the shorter commands, as well as auto-running the commands, and interacting with them further such as providing feedback to refine our commands.

Just make sure you install it globally using the -g tag.

Head to the @githubnext/github-copilot-cli page on npmjs, here.

Then you can see the most up-to-date install command which should be something like:

1
npm install -g @githubnext/github-copilot-cli

Once it is installed you should sign in by running:

1
github-copilot-cli auth

At the time of writing it seems if you’re authorized using gh then this step isn’t required, but in the future it may be - I assume when it’s fully released this will be required.

You can upgrade it in the future by running:

1
npm install -g @githubnext/github-copilot-cli

Activating GitHub Copilot commands

Finally, we can get to setting up the shorter commands. For this, we’re working with Aliases. Simplified text snippets to fire off larger commands.

Linux and Mac

On Linux and Mac it is simple. We’ll edit our .bashrc or .zshrc files.

Use your editor of choice and edit them. For example:

Bash
1
nano ~/.bashrc

At the bottom you’ll add:

Bash
1
eval "$(github-copilot-cli alias -- "$0")"

Windows

This is more complicated, and I didn’t find steps anywhere… So, I made my own.

This requires PowerShell as we can easily make Aliases. I’m sure you could set this up elsewhere in a similar fashion.

Open a new Terminal window and select PowerShell, or just a PowerShell window if you don’t have Terminal installed.

Create a new PowerShell config file if it does not already exist for your user:

Powershell
1
New-Item -Path $PROFILE -ItemType File

Now, open the config file with Notepad:

Powershell
1
notepad $PROFILE

Then, enter the following text and save the file:

Powershell
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function ?? {
    github-copilot-cli what-the-shell "$args"
}

function git? {
    github-copilot-cli git-assist "$args"
}

function gh? {
    github-copilot-cli gh-assist "$args"
}

This adds functionality for the ??, git? and gh? commands.

All you need to do now is reload your PowerShell terminal. Simply close and re-open Terminal or PowerShell.

Now you can run the above commands like any other user.


Conclusion

I would expect this to pump out more Unix-like commands for Linux or Mac, as that’s what this tool is designed for (I assume).

You can, however, install it on Windows as I’ve just shown you in this article, and the video at the top.

Would I reccommend you use this? Yeah. People using AI are going to be faster at accomplishing goals than those without in a lot of cases. The outcome may be learning less, but if you’re aiming for speed and not nessecarily accuracy then this is a super quick way to get going.

For more experienced CLI users I wouldn’t imagine much use for this, especially those on Arch Linux, for example, as the use of man for “Manual” is prolific.

However, do with this knowledge as you please, you now know how to get started with using this right now! If you have a GitHub Copilot subscription, give this a try.

TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Change privacy settings Contact