DEV Community

Cover image for What is GitHub CLI?
Dhananjay Haridas
Dhananjay Haridas

Posted on

What is GitHub CLI?

Introduction

Most developers interact with GitHub through a web browser. We open GitHub, create repositories, review pull requests, manage issues, and create releases through the website.

But what if you could perform all those actions directly from your terminal?

That is exactly what GitHub CLI, commonly known as gh, allows you to do.

GitHub CLI is an official command-line tool developed by GitHub that enables developers to work with GitHub without constantly switching between their code editor, terminal, and browser.

By the end of this guide, you will understand:

  • What GitHub CLI is
  • Why it exists
  • How to install it
  • How authentication works
  • Common commands every developer should know
  • Real-world workflows
  • Best practices and tips

What is GitHub CLI?

GitHub CLI is a command-line application that lets you interact with GitHub from your terminal.

Instead of visiting:

https://github.com
Enter fullscreen mode Exit fullscreen mode

and clicking through menus, you can perform GitHub operations using commands.

For example:

gh repo create
Enter fullscreen mode Exit fullscreen mode

creates a repository.

gh pr create
Enter fullscreen mode Exit fullscreen mode

creates a pull request.

gh issue create
Enter fullscreen mode Exit fullscreen mode

creates an issue.

gh release create
Enter fullscreen mode Exit fullscreen mode

creates a release.


Why Was GitHub CLI Created?

Before GitHub CLI existed, developers typically had three options:

Option 1: Use the GitHub Website

Pros:

  • Easy to understand
  • Visual interface

Cons:

  • Constant context switching
  • Slower for repetitive tasks

Option 2: Use Git Commands

Git commands help manage source control:

git commit
git push
git pull
git branch
Enter fullscreen mode Exit fullscreen mode

However, Git itself does not manage:

  • Pull Requests
  • Issues
  • Releases
  • Discussions

These are GitHub features.


Option 3: Use GitHub APIs

GitHub provides APIs.

Example:

curl \
  -H "Authorization: Bearer TOKEN" \
  https://api.github.com/repos/user/project/issues
Enter fullscreen mode Exit fullscreen mode

This works but can become complex.


GitHub CLI bridges this gap.

It provides a simple developer-friendly interface over GitHub APIs.


Git vs GitHub CLI

Many beginners confuse Git and GitHub CLI.

Git GitHub CLI
Version control system GitHub management tool
Works locally Communicates with GitHub
git push gh pr create
git branch gh issue create
git merge gh release create

Think of it like this:

Git = Manage code history

GitHub CLI = Manage GitHub platform features
Enter fullscreen mode Exit fullscreen mode

Installing GitHub CLI

Ubuntu

sudo apt update
sudo apt install gh
Enter fullscreen mode Exit fullscreen mode

Verify:

gh --version
Enter fullscreen mode Exit fullscreen mode

Example output:

gh version 2.70.0
Enter fullscreen mode Exit fullscreen mode

macOS

Using Homebrew:

brew install gh
Enter fullscreen mode Exit fullscreen mode

Windows

Using Winget:

winget install GitHub.cli
Enter fullscreen mode Exit fullscreen mode

First-Time Authentication

After installation:

gh auth login
Enter fullscreen mode Exit fullscreen mode

You will see options such as:

? What account do you want to log into?
GitHub.com
Enter fullscreen mode Exit fullscreen mode

Choose:

GitHub.com
Enter fullscreen mode Exit fullscreen mode

Then:

HTTPS
Enter fullscreen mode Exit fullscreen mode

Then:

Login with browser
Enter fullscreen mode Exit fullscreen mode

GitHub CLI will generate a code.

Example:

First copy your one-time code:
ABCD-EFGH
Enter fullscreen mode Exit fullscreen mode

Open the browser and authenticate.


Check Authentication Status

gh auth status
Enter fullscreen mode Exit fullscreen mode

Example:

Logged in to github.com
Enter fullscreen mode Exit fullscreen mode

Creating a Repository

Create a repository directly from the terminal.

gh repo create my-project
Enter fullscreen mode Exit fullscreen mode

Interactive mode will ask:

Public or Private?
Enter fullscreen mode Exit fullscreen mode

Choose your preference.


Cloning a Repository

Traditional Git:

git clone https://github.com/user/project.git
Enter fullscreen mode Exit fullscreen mode

GitHub CLI:

gh repo clone user/project
Enter fullscreen mode Exit fullscreen mode

Example:

gh repo clone octocat/demo
Enter fullscreen mode Exit fullscreen mode

Viewing Repository Information

gh repo view
Enter fullscreen mode Exit fullscreen mode

Example output:

Repository:
user/project

Description:
My project

Stars:
120
Enter fullscreen mode Exit fullscreen mode

Creating Issues

Issues are used to track bugs and feature requests.

Create one:

gh issue create
Enter fullscreen mode Exit fullscreen mode

Interactive prompts appear.

You can also provide everything directly:

gh issue create \
  --title "Login Bug" \
  --body "Users cannot log in"
Enter fullscreen mode Exit fullscreen mode

Listing Issues

gh issue list
Enter fullscreen mode Exit fullscreen mode

Example:

#23 Login Bug
#24 Add Dark Mode
#25 Improve Performance
Enter fullscreen mode Exit fullscreen mode

Viewing a Specific Issue

gh issue view 23
Enter fullscreen mode Exit fullscreen mode

Creating Pull Requests

One of the most powerful features.

After pushing a branch:

git push origin feature/login
Enter fullscreen mode Exit fullscreen mode

Create a PR:

gh pr create
Enter fullscreen mode Exit fullscreen mode

GitHub CLI asks:

Title?
Description?
Base branch?
Enter fullscreen mode Exit fullscreen mode

Then creates the pull request.


Listing Pull Requests

gh pr list
Enter fullscreen mode Exit fullscreen mode

Example:

#45 Add Login Feature
#46 Fix Database Error
Enter fullscreen mode Exit fullscreen mode

Viewing Pull Requests

gh pr view 45
Enter fullscreen mode Exit fullscreen mode

Checking Out a Pull Request

Instead of manually fetching branches:

gh pr checkout 45
Enter fullscreen mode Exit fullscreen mode

This automatically switches to the PR branch.


Reviewing Pull Requests

Approve:

gh pr review 45 --approve
Enter fullscreen mode Exit fullscreen mode

Request changes:

gh pr review 45 --request-changes
Enter fullscreen mode Exit fullscreen mode

Comment:

gh pr review 45 --comment
Enter fullscreen mode Exit fullscreen mode

Merging Pull Requests

gh pr merge 45
Enter fullscreen mode Exit fullscreen mode

Options:

gh pr merge 45 --merge
Enter fullscreen mode Exit fullscreen mode
gh pr merge 45 --squash
Enter fullscreen mode Exit fullscreen mode
gh pr merge 45 --rebase
Enter fullscreen mode Exit fullscreen mode

Working with Releases

A release is a published version of software.

Example:

v1.0.0
v1.1.0
v2.0.0
Enter fullscreen mode Exit fullscreen mode

Create a Release

gh release create v1.0.0
Enter fullscreen mode Exit fullscreen mode

Add Release Notes

gh release create v1.0.0 \
  --notes "Initial release"
Enter fullscreen mode Exit fullscreen mode

Upload Files

gh release create v1.0.0 \
  dist/app.tar.gz
Enter fullscreen mode Exit fullscreen mode

This is likely what happened in your project.

Your Makefile probably executes something similar to:

gh release create \
  v1.0.0 \
  dist/registry-data-v1.0.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

Without GitHub CLI installed, that step fails.


Viewing Releases

gh release list
Enter fullscreen mode Exit fullscreen mode

Example:

v1.0.0
v1.1.0
v2.0.0
Enter fullscreen mode Exit fullscreen mode

Download Release Assets

gh release download v1.0.0
Enter fullscreen mode Exit fullscreen mode

Working with GitHub Actions

View workflows:

gh workflow list
Enter fullscreen mode Exit fullscreen mode

View workflow runs:

gh run list
Enter fullscreen mode Exit fullscreen mode

Inspect a run:

gh run view
Enter fullscreen mode Exit fullscreen mode

Watch live logs:

gh run watch
Enter fullscreen mode Exit fullscreen mode

Working with Gists

Create a gist:

gh gist create notes.txt
Enter fullscreen mode Exit fullscreen mode

List gists:

gh gist list
Enter fullscreen mode Exit fullscreen mode

Useful Commands Every Developer Should Know

Authentication

gh auth login
gh auth status
gh auth logout
Enter fullscreen mode Exit fullscreen mode

Repositories

gh repo create
gh repo clone
gh repo view
Enter fullscreen mode Exit fullscreen mode

Issues

gh issue create
gh issue list
gh issue view
Enter fullscreen mode Exit fullscreen mode

Pull Requests

gh pr create
gh pr list
gh pr view
gh pr checkout
gh pr merge
Enter fullscreen mode Exit fullscreen mode

Releases

gh release create
gh release list
gh release view
Enter fullscreen mode Exit fullscreen mode

Real-World Example Workflow

Imagine you are implementing a feature.

Step 1

Create a branch:

git checkout -b feature/payment
Enter fullscreen mode Exit fullscreen mode

Step 2

Write code.


Step 3

Commit changes:

git add .
git commit -m "Add payment support"
Enter fullscreen mode Exit fullscreen mode

Step 4

Push:

git push origin feature/payment
Enter fullscreen mode Exit fullscreen mode

Step 5

Create PR:

gh pr create
Enter fullscreen mode Exit fullscreen mode

Step 6

Review PR:

gh pr view
Enter fullscreen mode Exit fullscreen mode

Step 7

Merge:

gh pr merge
Enter fullscreen mode Exit fullscreen mode

Step 8

Create Release:

gh release create v1.0.0
Enter fullscreen mode Exit fullscreen mode

Entire workflow completed without opening GitHub in a browser.


Advantages of GitHub CLI

Faster Workflow

No browser switching.

Automation Friendly

Perfect for scripts and CI/CD pipelines.

Consistent Interface

Everything from one terminal.

Developer Productivity

Reduces repetitive work.

Official Tool

Maintained by GitHub.


When Should You Use GitHub CLI?

Use GitHub CLI if you:

  • Work with GitHub daily
  • Create pull requests frequently
  • Manage releases
  • Handle issues regularly
  • Build automation scripts
  • Work in DevOps or platform engineering

Common Beginner Mistakes

Forgetting Authentication

gh auth login
Enter fullscreen mode Exit fullscreen mode

must be completed first.


Confusing Git with GitHub CLI

Remember:

Git manages code history.

GitHub CLI manages GitHub features.
Enter fullscreen mode Exit fullscreen mode

Missing Permissions

Your GitHub account must have permissions for the repository.


Not Updating GitHub CLI

Keep it updated:

sudo apt update
sudo apt upgrade gh
Enter fullscreen mode Exit fullscreen mode

Summary

GitHub CLI (gh) is GitHub's official command-line tool that allows developers to manage repositories, issues, pull requests, releases, workflows, and many other GitHub features directly from the terminal.

For a junior developer, learning GitHub CLI provides several benefits:

  • Faster development workflows
  • Less dependence on the browser
  • Easier automation
  • Better understanding of GitHub operations
  • Improved productivity in professional software teams

If you're already comfortable with commands like:

git add
git commit
git push
Enter fullscreen mode Exit fullscreen mode

then learning:

gh pr create
gh issue create
gh release create
Enter fullscreen mode Exit fullscreen mode

is the next natural step toward becoming a more efficient developer.

Top comments (0)