What is GitHub CLI? (original) (raw)

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.

Features of GitHub CLI

Some features of GitHub CLI:

Benefits of Using GitHub CLI

Here are the benefits of using GitHub CLI:

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

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:

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]

Commonly Used Commands and Flags

Here are some common GitHub CLI commands:

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

To Fork a Repository:

gh repo fork

**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

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

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

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

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 --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.

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