MW

How-To · Version Control

GitHub CLI (`gh`) — Install, Authenticate, and Use from Your Terminal (2026)

GitHub CLI brings pull requests, issues, releases, and workflows straight to your terminal. Install in one command, authenticate once, and never open github.com again.

Jan 24, 2025 7 min read Any platform beginner
Advertisement

GitHub CLI (gh) is GitHub’s official command-line tool. It brings pull requests, issues, releases, GitHub Actions, and repo management directly into your terminal — no more Alt-Tab to github.com.

Terminal — typical gh workflow
$ gh pr create --title "Add empire-shells QuickAnswer"
Creating pull request for mahesh:feat/quick-answer into main in maheshwaghmare/empire https://github.com/maheshwaghmare/empire/pull/421
$ gh pr view --web
Opening https://github.com/maheshwaghmare/empire/pull/421 in your browser.

This guide covers install + auth (the two things you only do once), then every gh command you’ll actually use day-to-day.

Installation

Windows

The fastest option is winget (built into Windows 10/11):

PowerShell — winget install
C:\> winget install --id GitHub.cli
Found GitHub CLI [GitHub.cli] Version 2.39.1 Successfully installed
C:\> gh --version
gh version 2.39.1 (2023-12-13) https://github.com/cli/cli/releases/tag/v2.39.1

Alternatives — choco install gh or scoop install gh if you use those package managers.

macOS

Homebrew is the standard install:

Terminal — Homebrew install
$ brew install gh
==> Pouring gh--2.39.1.arm64_sonoma.bottle.tar.gz ==> Installed /opt/homebrew/Cellar/gh/2.39.1
$ gh --version
gh version 2.39.1 (2023-12-13)

Linux

Debian/Ubuntu — official GitHub apt repo (the version in default apt repos is usually stale):

bash — Ubuntu/Debian via official repo
$ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
$ sudo apt update && sudo apt install gh
Setting up gh (2.39.1) ...
$ gh --version
gh version 2.39.1

Fedora/RHEL: sudo dnf install 'dnf-command(config-manager)' && sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && sudo dnf install gh

Arch: sudo pacman -S github-cli

Authentication

You only do this once per machine. gh auth login walks you through it interactively:

Terminal — first-time auth
$ gh auth login
? What account do you want to log into? GitHub.com ? What is your preferred protocol for Git operations? HTTPS ? Authenticate Git with your GitHub credentials? Yes ? How would you like to authenticate GitHub CLI? Login with a web browser ! First copy your one-time code: ABCD-1234 - Press Enter to open github.com in your browser... Authentication complete. - gh config set -h github.com git_protocol https Configured git protocol Logged in as your-username

Check who you’re logged in as

Terminal — verify auth
$ gh auth status
github.com Logged in to github.com account your-username (keyring) - Active account: true - Git operations protocol: https - Token: gho_************************************ - Token scopes: 'gist', 'read:org', 'repo', 'workflow'

Repository management

The 5 commands you’ll use daily:

Terminal — repo commands
$ gh repo create my-new-app --public --clone
Created repository your-username/my-new-app on GitHub Cloned to /Users/you/my-new-app
$ gh repo clone vercel/next.js
Cloning into 'next.js'...
$ gh repo fork vercel/next.js --clone
Created fork your-username/next.js Cloned fork
$ gh repo view --web
Opening https://github.com/your-username/my-new-app in your browser.

Other useful repo commands:

  • gh repo list — your repos
  • gh repo list organization-name — org repos
  • gh repo edit --description "New description" — update repo metadata
  • gh repo view owner/repo --json name,description,isPrivate — JSON output for scripting

Pull requests

This is where gh really earns its place. Top GSC queries on this page hit gh pr view --web and gh pr checkout specifically.

Create a PR

Terminal — gh pr create
$ git checkout -b feat/quick-answer && git push -u origin feat/quick-answer
$ gh pr create --title "Add empire-shells QuickAnswer" --body "Adds the QuickAnswer card to the how-to hero right side. Wires JSON-LD HowTo step[]."
Pull request created: https://github.com/owner/repo/pull/421

gh pr create defaults to your current branch. Add --draft for draft PRs, --web to open the create form in browser instead.

View / open / merge

Terminal — gh pr lifecycle
$ gh pr view
#421 Add empire-shells QuickAnswer Open · your-username wants to merge 3 commits into main from feat/quick-answer Checks passing + 142 -38 across 8 files
$ gh pr view --web
Opening https://github.com/owner/repo/pull/421 in your browser.
$ gh pr checkout 421
remote: Enumerating objects: 18, done. Switched to branch 'feat/quick-answer'
$ gh pr merge 421 --squash --delete-branch
Squashed and merged pull request #421 Deleted branch feat/quick-answer

Daily PR commands

CommandWhat it does
gh pr listList open PRs in current repo
gh pr list --state allInclude closed/merged PRs
gh pr checkout <number>Switch local branch to PR’s branch
gh pr review --approveApprove current PR
gh pr review --request-changes -b "needs work"Request changes with comment
gh pr diffShow PR diff in terminal
gh pr statusPRs relevant to you (assigned, mentioned, reviewing)

Issues

Terminal — gh issue commands
$ gh issue create --title "Bug in OSSettingsMockup window controls" --body "Window-control icons render as Unicode glyphs instead of SVG."
Created issue your-username/empire#142
$ gh issue list --label bug --limit 5
#142 Bug in OSSettingsMockup window controls bug about 1 hour ago #138 Callout icons should be SVG not Unicode bug about 4 hours ago ...
$ gh issue close 142 --comment "Fixed in #421"
Closed issue #142

GitHub Actions workflows

Terminal — gh workflow + gh run
$ gh workflow list
Deploy active 12345 Test active 12346 Lint active 12347
$ gh workflow run Deploy
Created workflow run for "Deploy"
$ gh run list --limit 3
X Deploy main push 2m45s abc1234 Test main push 1m22s abc1234 Lint main push 35s abc1234
$ gh run watch
build (4m12s) test (1m22s) deploy (2m45s) Run Deploy completed with success

Best practices

  1. Authenticate once per machinegh auth login stores credentials in your OS keychain
  2. Default to HTTPS — easier than SSH for new setups, gh handles credential helpers automatically
  3. Pin to a version in CI — install gh via apt/brew pinned to a known good version for reproducible builds
  4. Use --web when you want browsergh pr view --web, gh repo view --web, gh issue view --web
  5. JSON output for scripts — every gh X view command supports --json field1,field2 for shell scripting

Conclusion

GitHub CLI cuts your context-switching overhead dramatically once installed. The 30-second install + 1-minute auth pays back the first time you gh pr create from your editor’s integrated terminal without breaking flow.

Most common commands to memorize:

  • gh pr create — create PR from current branch
  • gh pr view --web — open current PR in browser
  • gh pr checkout <n> — check out someone else’s PR locally
  • gh issue list — what’s open in this repo
  • gh repo clone owner/repo — Git’s clone plus auth + remote setup
GitHub CLI Git Command Line Development
Advertisement

Get weekly notes in your inbox

Practical tips, tutorials and resources. No spam.