What is GitHub CLI?

Last Updated : 19 Jan, 2026

GitHub CLI is a command-line tool by GitHub that enables developers to manage and interact with GitHub features directly from the terminal.

  • Allows performing GitHub tasks without using the web interface.
  • Bridges the gap between local development and GitHub.
  • Supports repository management from the command line.
  • Enables creating and managing issues and pull requests.
  • Helps monitor and manage GitHub Actions workflows.
  • Provides access to most features available on the GitHub website.

Features of GitHub CLI

Some features of GitHub CLI:

  • Repository Management: Easily create, clone, view, and manage repositories.
  • Pull Requests and Issues: Create, view, and manage pull requests and issues directly from the terminal
  • GitHub Actions: Interact with workflows and manage workflow runs.
  • Authentication: Provides a secure way to authenticate with your GitHub account, supporting SSH keys, tokens, and OAuth.
  • Custom Scripting: Allows automation of repetitive tasks using custom scripts and aliases

Benefits of Using GitHub CLI

Here are the benefits of using GitHub CLI:

  • Saves time by avoiding switching between the browser and terminal
  • Allows creating issues with a single command
  • Improves workflow efficiency and productivity
  • Keeps developers focused within the command-line environment
  • Reduces repetitive manual steps when working with GitHub

Installation and Setup

On Windows, GitHub CLI can be installed using winget, the built-in Windows package manager, which enables command-line–based installation and management of software packages.

Installing GitHub CLI on Windows, macOS, and Linux

Windows:

Run the following command:

winget install --id GitHub.GitHubCli
  • winget install: Tells Windows to install a new software package.
  • --id GitHub.GitHub.cli: Installs the GitHub CLI on Windows using the winget package manager.

macOS:

GitHub CLI can be installed using Homebrew, a popular package manager. Open the terminal and execute:

brew install gh

This command downloads and installs the gh (GitHub CLI) package along with its dependencies.

Linux:

GitHub CLI can be installed using the system’s package manager. For Ubuntu, run:

sudo apt install gh

This command installs the gh package along with its required dependencies.

Authenticating with GitHub Account

After installation, authenticate GitHub CLI to link it with your GitHub account.

Authentication Command:

gh auth login

Steps to Authenticate:

  • Run gh auth login in the terminal.
  • Select an authentication method (browser-based authentication is recommended).
  • The CLI opens a browser link where you sign in to GitHub.
  • Once completed, GitHub confirms the CLI is successfully connected.
  • Verify authentication using:
gh auth status

GitHub CLI is easy to navigate, and its command structure is intuitive.

Command Structure and Syntax

GitHub CLI commands follow a simple and straigntforward pattern:

gh [command] [subcommand] [flags]
  • Command: The main action you want to perform (e.g., repo, issue, pr).
  • Subcommand: A specific task within the command (e.g., create, list, view).
  • Flags: Optional parameters that modify the command's behavior (e.g., --title, --body).

Commonly Used Commands and Flags

Here are some common GitHub CLI commands:

  • Creating a repository: gh repo create
  • Listing issues: gh issue list
  • Creating a pull request: gh pr create
  • Viewing a repository's details: gh repo view

To see all available commands and options, we can always run:

gh help

Managing Repositories with GitHub CLI

Creating a new GitHub repository directly from the terminal can be done using the following command.

Creating and Cloning Repositories

To create a new repository, run:

gh repo create my-repo-name

To clone an existing repository, use:

gh repo clone owner/repo-name

Managing Branches and Pull Requests

GitHub CLI allows us to handle issues and pull requests (PRs) without leaving the terminal.

Commands:

Switching branches or creating pull requests is simple with GitHub CLI. To create a new branch:

git checkout -b new-branch-name

Then, to create a pull request:

gh pr create --title "Your PR Title" --body "Description of your PR"

Pushing and Pulling Changes

Push our changes to GitHub with:

git push origin branch-name

And pull the latest changes with:

git pull

Working with GitHub Actions

GitHub CLI also supports GitHub Actions, allowing us to manage workflows directly from your terminal.

Triggering and Monitoring Workflows

You can manually trigger workflows using:

gh workflow run workflow-name

And monitor the status of workflows with:

gh run list

Managing Workflow Runs and Logs

To see detailed logs of a workflow run:

gh run view run-id --log

Cloning and Forking Repositories

Cloning and forking are essential tasks when working on projects from other repositories.

Commands:

To Clone a Repository:

gh repo clone <repository-name>

To Fork a Repository:

gh repo fork <repository-url>

Example:

Cloning a Repository:

gh repo clone example-repo

Forking a Repository:

gh repo fork https://github.com/username/repository-name

Interacting with GitHub Actions

GitHub Actions allows us to automate workflows directly from our repository. With GitHub CLI, we can manage and view these workflows on Windows.

Commands:

To List All Workflows:

gh workflow list

To View Workflow Runs:

gh run list

Working with Gists

Gists are lightweight repositories for sharing small code or text snippets via GitHub CLI.

Commands:

To Create a New Gist:

gh gist create <file>

To List Our Gists:

gh gist list

Updating GitHub CLI

We can update GitHub CLI to the latest version with features and fixes using winget.

Update Command:

winget upgrade --id GitHub.cli
  • winget upgrade: Checks for updates for the specified package.
  • --id GitHub.cli: Identifies the GitHub CLI package for the upgrade.

Managing Repositories with GitHub CLI

Managing repositories is one of the most common task which we perform with GitHub CLI.

Creating and Cloning Repositories

Create a new repository:

gh repo create my-new-repo

Clone an existing repository:

gh repo clone <repository-name>

Working with GitHub Actions

GitHub CLI supports managing GitHub Actions, allowing control of automated workflows triggered by repository events.

Triggering and Monitoring Workflows

Trigger a workflow manually:

gh workflow run <workflow-name>

Monitor workflow runs:

gh run list

Managing Workflow Runs and Logs

To inspect a specific GitHub Actions workflow run, we can view its logs directly from the GitHub CLI.

gh run view <run-id> --log

Integrating GitHub Actions Commands in CI/CD Pipelines

We can use GitHub CLI commands to enhance our Continuous Integration/Continuous Deployment (CI/CD) pipelines, ensuring smooth automation and better control over our workflows.

Advanced Features and Integrations

GitHub CLI is not only used for performing basic tasks. We can perform some advanced operation using GitHub CLI:

Managing Gists with GitHub CLI

Gists are a simple way to share snippets of code. We can create, list, and manage your Gists with commands like:

gh gist create my-code-snippet.py

Interacting with Releases and Tags

To manage releases and tags, GitHub CLI provides commands to create, list, and delete releases:

gh release create v1.0.0

Extending GitHub CLI with Custom Scripts and Aliases

We can write our own scripts and integrate them into GitHub CLI, or create aliases for commands you use frequently to save time.

Example:

gh alias set prlist "pr list --state all"

Best Practices and Tips

Below some best practices are given:

Streamlining Workflow with Shortcuts and Aliases

Create aliases for our most-used commands to speed up your workflow.

Example:

gh alias set co "pr checkout"

Automating Tasks Using Scripts

Streamlines repetitive GitHub workflows using scripted CLI commands.

  • Automates branch creation and code pushes.
  • Creates pull requests programmatically.

Troubleshooting Common Issues

We can troubleshoot by checking the command syntax, ensuring our GitHub CLI is up to date, or consulting the documentation using command:

gh help <command>
Comment
Article Tags:

Explore