linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Tools/gh-cli

kb/tools ── Tools ── beginner

GitHub CLI (gh)

The official CLI from GitHub. Works with GitHub objects (PRs, issues, Actions, releases) that plain Git does not know about. Not a replacement for git, but a second-layer complement. Install via brew/apt/winget; authenticate with `gh auth login`.

view as markdownaka: github-cli, gh-tool

gh is the official command-line tool from GitHub. Unlike git, which works with the local .git/ directory and pushes commits, gh talks to the GitHub API: it creates PRs, lists issues, views Actions runs, and downloads releases. These things live in GitHub's database, not in Git objects.

Installation

bash
# macOS
brew install gh
# Ubuntu/Debian
sudo apt install gh
# Windows
winget install GitHub.cli
scoop install gh
# verify
gh --version

The full list of installers is at cli.github.com.

Authentication

bash
gh auth login

The command asks a few questions (GitHub.com or Enterprise, HTTPS or SSH, browser or token) and stores an OAuth token in the OS keychain. After that:

bash
gh auth status      # which account is active, which scopes
gh auth switch      # switch between multiple accounts
gh auth logout      # revoke

Main commands

bash
# repositories
gh repo clone owner/repo
gh repo fork owner/repo --clone   # fork + clone + remote setup
gh repo create my-project --public --source=. --push
# pull requests
gh pr create -t "fix login" -b "Fixes #142"
gh pr list --author "@me"
gh pr view 123
gh pr checkout 123             # check out any PR branch locally
gh pr review --approve
gh pr merge --squash --delete-branch
gh pr checks --watch           # watch CI status in real time
# issues
gh issue create -t "Bug: ..." -b "..."
gh issue list --label bug
# actions
gh workflow run ci.yml
gh run list --workflow ci.yml
gh run view 12345 --log
gh run rerun --failed

JSON output for scripts

Almost every command accepts --json with a field list:

bash
gh pr list --json number,title,author \
  | jq -r '.[] | "\(.number) - \(.title) by \(.author.login)"'

To see the valid field names, pass --json with no argument; the error message lists all available fields.

Aliases

bash
gh alias set co 'pr checkout'
gh alias set prs 'pr list --author "@me"'

Aliases are stored in ~/.config/gh/config.yml. They accept $1, $2 for argument substitution.

Escape hatch: gh api

When there is no native command, you have raw access to REST or GraphQL:

bash
gh api repos/cli/cli/contributors --jq '.[].login'
gh api graphql -f query='query { viewer { login } }'

gh handles authentication, pagination, and retries for you.

When gh is faster than the browser

  • Creating a PR from the current branch (gh pr create).
  • Checking out someone else's PR for testing (gh pr checkout).
  • Viewing CI logs with grep.
  • Batch operations and scripts.
  • Creating an issue without leaving the terminal.

When the browser is more convenient

  • Inline code review (selecting lines with the mouse).
  • Long discussions with multiple participants.
  • Large diffs spanning many files.
  • Repository settings and organization management.

Both tools coexist. The terminal for speed, the browser for visual review. Details are in chapter 16.

§ команды

bash
gh auth login

Authenticate and configure the git credential helper

bash
gh pr create -t 'title' -b 'body'

Create a PR from the current branch

bash
gh pr checkout 123

Check out the branch for PR #123 locally, including PRs from forks

bash
gh pr merge --auto --squash

Enable auto-merge: merges when all checks pass

bash
gh run view --log | grep -i error

Download logs from the latest CI run and search for errors

§ см. также

  • pull-requestPull Request (PR)A request to merge a branch into the main branch after passing review and CI. On GitHub/GitLab/Bitbucket it is the standard mechanism for collaborative work. Technically it is not a Git command but a hosting feature built on top of branches and commits.
  • code-reviewCode reviewReading and discussing another developer's code before merge. The primary goal is sharing context, not finding bugs (bugs are a side effect). A good review improves the code and spreads knowledge of the system across the team.
  • draft-prDraft pull requestA PR state that signals "work is not done, do not review yet." CI runs on draft PRs, but reviewers are not assigned automatically and the merge button is blocked. Promote to a regular PR with `gh pr ready` or the "Ready for review" button.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies