GitHub CLI (gh) on Ubuntu: Complete Setup & Workflow Guide

Overview

Modern software engineering moves significantly faster when context switching between browser dashboards and the terminal is minimized. The official GitHub CLI (gh) consolidates repository administration, issue tracking, and pull request lifecycle operations directly within your shell environment. This guide walks through configuring the official upstream repository on Ubuntu, verifying authentication status, and mastering essential command sequences designed to streamline day-to-day developer productivity.

Installing GitHub CLI (gh) on Ubuntu and Verifying Setup

Before configuring external repositories, verify whether curl is present on your system; if missing, fetch and configure it quietly via APT.

type -p curl >/dev/null || (apt-get update -qq && apt-get install -y curl)

Retrieve GitHub’s official signing key over a secure channel and store the armored binary key directly inside the designated system keyring location.

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg

Assign broad read permissions to the newly downloaded keyring file so unprivileged processes and APT package management routines can validate archive integrity without permission hurdles.

chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg

Append the authenticated GitHub CLI repository entry to your system’s package source list, dynamically adapting the declaration to your host’s CPU architecture.

echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main” | tee /etc/apt/sources.list.d/github-cli.list > /dev/null

Synchronize package indexes against newly configured endpoints and complete the installation of the latest gh binary.

apt-get update -qq && apt-get install -y gh

Executing gh --version reports the currently active binary build, platform target, and relevant upstream release links.
⚙️ [Core Subcommands & Capabilities]

auth : Handles account logins, credential validation, token refreshes, and active session inspection.
repo : Creates, forks, clones, archives, and inspects remote codebases from the command line.
issue : Drives the issue tracking lifecycle, covering creation, querying, updating, and closure.
pr : Coordinates pull request reviews, branch checkouts, status checks, diff views, and merges.
workflow : Lists, inspects, enables, and halts GitHub Actions automated workflows.
run : Inspects real-time or historical CI/CD job runs and streams detailed diagnostic logs.
release : Automates tag creation, changelog assembly, and release asset uploads.
alias : Maps verbose or frequently combined CLI arguments to concise, custom shorthand triggers.
config : Tunes environmental defaults, including preferred command-line editors and Git transport protocols (HTTPS vs. SSH).

gh –version

Validating Authentication State and Accessing Integrated Manuals

Running gh auth status || true interrogates existing authentication tokens and active account associations, guaranteeing non-zero exit codes do not disrupt non-interactive setup scripts.

gh auth status || true

Invoke gh --help to reveal available core command groups, flags, and command syntax trees tailored for quick lookups during active development.

gh –help

Inspecting and Cloning Repositories via CLI

Set up an isolated scratch directory to explore command-line repository interactions without cluttering your primary project directories.

mkdir -p ~/gh_workspace && cd ~/gh_workspace

Query remote repository metadata instantly without firing up a browser: passing JSON selector flags pulls repository names, summaries, and stargazer metrics straight into structured text output.

gh repo view cli/cli –json name,description,stargazerCount

Execute gh repo clone while passing standard underlying Git options—such as shallow clone depth constraints—behind the -- separator to drastically minimize bandwidth consumption and download duration.

gh repo clone cli/cli – –depth 1 sample_repo

Navigate into the cloned workspace and audit local working tree health to ensure working branches and commit tracking references initialized accurately.

cd sample_repo && git status

Streamlining Everyday Issue and Pull Request Workflows

Filter and display the top 5 tracked issues for the project, keeping your terminal uncluttered while surfacing immediate action items.

gh issue list –limit 5

Review active, non-merged pull requests awaiting code review or final merge authorization without leaving your terminal workspace.

gh pr list –state open –limit 5

Generate an instant, unified digest of all pull requests relevant to your profile, including review requests, authored submissions, and branches matching your current workspace checkout.

gh pr status

You now have a fully configured GitHub CLI installation running on Ubuntu, alongside essential command patterns to supercharge everyday development. Embedding gh into your terminal habits streamlines daily workflows, reduces friction, and allows you to manage repositories, reviews, and workflows with peak command-line efficiency.