Skip to main content

Installing and Using GitHub CLI

While the GitHub website is beautiful and easy to use, professional developers often find it faster to perform tasks directly from the command line. The GitHub CLI (gh) is the official tool that brings GitHubโ€™s issues, pull requests, and other features to your terminal.

At CodeHarborHub, we use gh to streamline our workflow and keep our focus on the code.

tip

Don't worry if you're new to the command line! The GitHub CLI is designed to be user-friendly, and this guide will help you get started step by step. By the end, you'll be able to manage your GitHub projects without ever leaving your terminal.

Why use the CLI?โ€‹

  1. Context Switching: You don't have to leave VS Code or your terminal to open a Pull Request.
  2. Automation: You can write scripts to create repositories or check status automatically.
  3. Speed: Most common actions (like cloning a repo or checking a PR) are 3x faster with a single command.

Installationโ€‹

Open PowerShell or Command Prompt and run:

winget install --id GitHub.cli

Getting Started: Authenticationโ€‹

Once installed, you need to link the CLI to your GitHub account. Run:

gh auth login

Follow the interactive prompts:

  • Select GitHub.com (unless you're using GitHub Enterprise).
  • Choose HTTPS or SSH.
  • Select Login with a web browser (this will open a page to authorize the app).

Essential Commands for Daily Workโ€‹

TaskCommandDescription
Repo Statusgh repo viewShows the README and basic info for the current repo.
List PRsgh pr listLists all open Pull Requests in the repository.
Check out PRgh pr checkout <number>Downloads a teammate's PR to your PC to test it.
Create PRgh pr createOpens a new Pull Request for your current branch.
View Issuesgh issue listShows all open bugs or tasks.

Common Workflow Exampleโ€‹

Imagine you want to start a new project for CodeHarborHub. Instead of clicking through the website:

  1. Create a new repo:
    gh repo create my-new-project --public --clone
  2. Change into the folder:
    cd my-new-project
  3. Open in VS Code:
    code .

You just set up a full project in 5 seconds!

The "Status" Viewโ€‹

One of the best features of gh is the Dashboard view. Run this to see everything happening with your work:

gh status

It shows your relevant Pull Requests, their review status, and if your GitHub Actions tests passed or failed.

tip

You can use the --web flag with almost any command (e.g., gh pr view --web) to instantly open that specific page in your browser if you need to see the full UI.