GitHub CLI and GitHub Copilot on macOS

Learn how to streamline your development workflow by setting up GitHub CLI and GitHub Copilot on your M2 MacBook Pro. This guide covers installation with Homebrew, authentication, and setting up useful aliases for enhanced productivity.

GitHub CLI and GitHub Copilot on macOS
Github Copilot

As a developer, efficiency is key. GitHub CLI and GitHub Copilot are two powerful tools that can significantly streamline your workflow. In this post, we’ll walk through setting up GitHub CLI using Homebrew, logging in via your web browser, and installing the GitHub Copilot extension directly from the CLI on your M2 MacBook Pro. Additionally, we'll cover setting up helpful aliases to further enhance your productivity.

Table of Contents

Installing GitHub CLI with Homebrew

GitHub CLI (gh) allows you to manage your GitHub repositories and workflows directly from your terminal. Here’s how to install and set it up on your M2 MacBook Pro:

Step 1: Install GitHub CLI with Homebrew

Homebrew is the preferred package manager for macOS. Open your terminal and run the following command to install GitHub CLI:

brew install gh

Step 2: Authenticate with GitHub

Once the installation is complete, you need to authenticate GitHub CLI with your GitHub account. Use the following command:

gh auth login

Choose the option to log in with your web browser. This will open a new browser window where you can authorize GitHub CLI to access your account. Once you approve the request, return to your terminal to confirm the authentication.

Step 3: Install the GitHub Copilot Extension

To install the GitHub Copilot extension for the CLI, use the following command:

gh extension install github/gh-copilot

To update the Copilot extension, you can use:

gh extension upgrade gh-copilot

Step 4: Set Up Aliases for zsh

Add the following line to your .zshrc file in your $HOME folder or in one of your shell setup files:

# gh cli
eval "$(gh copilot alias -- zsh)"

This will add two alias:

  • ghcs: Wrapper around gh copilot suggest to suggest a command based on a natural language description of the desired output effort.
    Supports executing suggested commands if applicable.
  • ghce: Wrapper around gh copilot explain to explain a given input command in natural language.

Example Usage of Aliases

Using ghcs (GitHub Copilot Suggest)

Let's say you want to create a new GitHub repository. You can use ghcs to get a suggested command:

ghcs "create a new repository called my-new-repo"

GitHub Copilot will suggest the appropriate command, such as:

gh repo create my-new-repo --public

You can then execute the command directly.

Example: ghcs "create a new repository called my-new-repo"

Using ghce (GitHub Copilot Explain)

If you come across a complex GitHub CLI command and want to understand what it does, use ghce:

ghce "gh repo clone owner/repo"

GitHub Copilot will provide a natural language explanation of the command, such as:

"This command clones the repository repo owned by owner to your local machine."

Example: ghce "gh repo clone owner/repo"


By integrating GitHub CLI and GitHub Copilot into your development workflow, you can enhance your productivity and streamline your coding tasks. GitHub CLI makes it easy to manage repositories and workflows directly from your terminal, while GitHub Copilot provides intelligent code suggestions that can help you write code more efficiently.

Setting up these tools on your M2 MacBook Pro is straightforward. By following the steps outlined above, you'll be well on your way to a more efficient and enjoyable coding experience. Give these tools a try and see how they can transform your development workflow!

Setting up GitHub Copilot in the CLI - GitHub Docs
Learn how to enable and install GitHub Copilot in the CLI.

Setup aliases and other usages of gh copilot extension:

Using GitHub Copilot in the CLI - GitHub Docs
You can use gh, the GitHub command line interface, to work with GitHub Copilot in the CLI.