GitHub CLI setup

Prepare to work with remote repositories on GitHub

Signup to GitHub

Sign up for a free GitHub account if you haven’t already. I recommend that you use a permanent, personal email.

Install the GitHub CLI

Let’s install the GitHub CLI, which will make working with remote GitHub repositories easier.

On MacOS

  1. Install Homebrew if you do not have it already. Run the following in the Terminal and follow the on-screen instructions:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Run brew install gh and follow the on-screen instructions.

On WSL or Ubuntu

  1. Paste the following into a Terminal:
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
	&& 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
  1. You will be prompted for your Ubuntu password.

Login with the GitHub CLI

Run gh auth login and follow the onscreen instructions to register your computer with GitHub.

  • Leave the default options selected in the CLI. You will hit Enter to open a web browser. Sign into GitHub with your GitHub credentials.
    GitHub CLI prompt to open browser from the terminal
  • Enter the code shown in the Terminal window.
    Enter CLI code in browser
  • Complete the authorization and leave the default options as-is.

Once you have finished, your Terminal and Browser should look like this:

CLI and browser success messages once linking finished

Last modified November 11, 2024.