Back to Resources Resource

GitHub CLI (gh) - GitHub in Your Terminal

Create PRs, review code, manage issues, and trigger workflows - all from your terminal. No browser context switching.

You're in the flow, coding in your terminal, and need to create a PR. Do you really want to open a browser, navigate to GitHub, fill out forms? GitHub CLI (gh) brings all of GitHub to your terminal - PRs, issues, actions, and more without leaving your workflow.

💻

Stay in Your Flow

Create PRs, manage issues, view workflow runs, and clone repos - all without opening a browser. GitHub in your terminal means no context switching.

Terminal-First GitHub

The GitHub CLI connects your terminal directly to GitHub's API, letting you accomplish common tasks faster than through the web interface:

Terminal $ gh pr create --title "Add auth" --body "..." Creating pull request for feature/auth into main https://github.com/user/repo/pull/42 $ gh issue list --label bug #23 Login fails on Safari bug #21 API rate limit error bug $ gh run view --log ✓ Build completed in 2m 15s ✓ Test completed in 4m 32s ✓ Deploy completed in 1m 08s $ API GitHub ↪ Pull Requests gh pr ● Issues gh issue ⚙ Actions gh run 📁 Repos gh repo 📄 Gists gh gist 🏷 Releases gh release

Run gh commands in your terminal to interact with all GitHub features through the API

Key Features

↪

PR Creation

Create, view, merge, and checkout PRs without leaving the terminal. Auto-fills title from branch name

📌

Issue Management

List, create, close, and comment on issues. Filter by labels, assignees, or milestones instantly

🔍

Code Review

Review PRs, view diffs, approve or request changes - all from your terminal with syntax highlighting

⚙

Actions & Workflows

View workflow runs, watch logs in real-time, re-run failed jobs, trigger manual workflows

Practical Examples

Pull Request Workflow - the most common use case for gh:

Terminal - PR workflow
# Create a PR from current branch
gh pr create --title "Add user authentication" --body "Implements JWT auth"

# Create PR and open in browser for final review
gh pr create --web

# Create draft PR
gh pr create --draft

# List open PRs assigned to you
gh pr list --assignee @me

# View PR details
gh pr view 42

# Check out a PR locally to test it
gh pr checkout 42

# View PR diff
gh pr diff 42

# Approve a PR
gh pr review 42 --approve

# Request changes with a comment
gh pr review 42 --request-changes --body "Please add tests"

# Merge a PR (squash)
gh pr merge 42 --squash --delete-branch

Issue Management - track and triage issues efficiently:

Terminal - Issue commands
# List all open issues
gh issue list

# List bugs assigned to you
gh issue list --label bug --assignee @me

# Create a new issue
gh issue create --title "Button not clickable on mobile" --label bug

# Create issue with body from file
gh issue create --title "Feature request" --body-file description.md

# View issue details
gh issue view 23

# Close an issue with a comment
gh issue close 23 --comment "Fixed in #42"

# Reopen an issue
gh issue reopen 23

# Add labels to an issue
gh issue edit 23 --add-label "priority:high"

# Assign issue to yourself
gh issue edit 23 --add-assignee @me

GitHub Actions - monitor and manage CI/CD:

Terminal - Actions commands
# List recent workflow runs
gh run list

# View a specific run
gh run view 12345

# Watch a run in real-time (live logs!)
gh run watch 12345

# View logs for a failed run
gh run view 12345 --log-failed

# Re-run failed jobs
gh run rerun 12345 --failed

# Trigger a workflow manually
gh workflow run deploy.yml

# Trigger with inputs
gh workflow run deploy.yml -f environment=staging

# List all workflows
gh workflow list

# View workflow file
gh workflow view deploy.yml

Why Developers Love It

  • ✓ No Context Switching - Stay in your terminal. Create PRs right after committing, no browser needed
  • ✓ Scriptable - Automate GitHub tasks in shell scripts, CI pipelines, or cron jobs
  • ✓ Faster Than Web UI - gh pr create is faster than clicking through forms
  • ✓ Live CI Logs - Watch Actions run in real-time with gh run watch
  • ✓ Full API Access - Use gh api to call any GitHub API endpoint
  • ✓ Works Everywhere - Windows, Mac, Linux. Install via brew, apt, winget, or download

Common Workflows

Workflow Commands
Feature Branch PR git checkout -b feature → git push -u origin → gh pr create
Review & Merge gh pr checkout 42 → gh pr diff → gh pr review --approve → gh pr merge
Bug Fix Workflow gh issue view 23 → fix code → gh pr create → gh issue close 23
Release Automation gh release create v1.0.0 --generate-notes
Clone & Fork gh repo clone owner/repo or gh repo fork --clone

Cheatsheet

Quick reference for the most useful gh commands:

Task Command
Create PR gh pr create
List open PRs gh pr list
Checkout PR gh pr checkout <number>
Merge PR gh pr merge --squash
Create issue gh issue create
View workflow runs gh run list
Watch CI live gh run watch
Clone repo gh repo clone owner/repo
Create release gh release create v1.0.0
Call any API gh api /repos/:owner/:repo

Pro Tips

🔗

Create Aliases for Common Commands

Use gh alias set to create shortcuts: gh alias set prc "pr create --web". Now gh prc creates a PR and opens it in browser.

🎯

Use gh api for Anything

Access any GitHub API: gh api /repos/:owner/:repo/contributors. Combine with jq for powerful queries: gh api /repos/:owner/:repo | jq '.stargazers_count'

📦

Extensions Ecosystem

Extend gh with community extensions: gh extension install dlvhdr/gh-dash for a beautiful PR dashboard. Browse at gh extension browse.

📄

Auto-Generate Release Notes

Use gh release create v1.0.0 --generate-notes to auto-generate changelog from merged PRs since last release. Saves hours of manual documentation.

🔧

Git + gh Power Combo

Chain git and gh: git push -u origin HEAD && gh pr create. Push and create PR in one command. Add to a git alias for maximum efficiency.

Getting Started

  1. 1

    Install GitHub CLI

    macOS: brew install gh | Windows: winget install GitHub.cli | Linux: apt install gh

  2. 2

    Authenticate with GitHub

    Run gh auth login and follow the prompts. Choose HTTPS or SSH, and authenticate via browser.

  3. 3

    Try Your First Command

    In any git repo, run gh pr list to see open PRs or gh issue list for issues.

  4. 4

    Explore with --help

    Every command has great help: gh pr --help, gh issue create --help. Tab completion works too!

Get GitHub CLI

Stop switching between terminal and browser. Bring GitHub into your command line workflow.

Install GitHub CLI

Explore More Resources