GitHub CLI — Manage GitHub Without Leaving the Terminal
gh is GitHub's official command-line tool. It brings pull requests, issues, releases, workflows, gists, and repository management directly to the terminal — no browser required for most day-to-day GitHub operations.
For SysAdmins, the key value is automation and integration. Anything you currently do by clicking around GitHub's web interface can be scripted with gh. That means it drops naturally into cron jobs, CI pipelines, post-deploy hooks, and AI-assisted workflows.
The AI angle: gh is the bridge between AI coding tools like aider and GitHub. When aider finishes a change, gh creates the PR. When Copilot suggests a fix, gh pushes it. The AI tools generate the code; gh handles the GitHub side of the delivery pipeline.
dnf install 'dnf-command(config-manager)' dnf config-manager --add-repo \ https://cli.github.com/packages/rpm/gh-cli.repo dnf install gh
curl -fsSL \ https://cli.github.com/packages/githubcli-archive-keyring.gpg \ | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [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 sudo apt update && sudo apt install gh
After install, authenticate once:
# Interactive login — opens browser or accepts token gh auth login # Check authentication status gh auth status # Login with a token (for headless/server environments) echo $GITHUB_TOKEN | gh auth login --with-token
GITHUB_TOKEN in your environment or pass it via --with-token. Fine-grained tokens are recommended — scope them to only the repositories and permissions needed.
| Command Group | What It Does |
|---|---|
gh repo | Create, clone, fork, view repositories |
gh pr | Create, review, merge, list pull requests |
gh issue | Create, view, close, assign issues |
gh workflow | List and trigger GitHub Actions workflows |
gh run | View and manage workflow run results |
gh release | Create and manage releases and assets |
gh gist | Create, list, and edit gists |
gh secret | Manage repository and org secrets |
gh api | Make authenticated calls to any GitHub API endpoint |
gh extension | Install community extensions to gh |
Clone, create, and manage repos without touching the browser.
# Clone a repo (smarter than git clone — sets up gh context) gh repo clone owner/repo-name # Create a new repo from current directory gh repo create my-new-repo --public --source=. --push # View repo info gh repo view # Fork a repo and clone the fork gh repo fork owner/repo --clone
The full PR lifecycle from the command line.
# Create a PR from current branch
gh pr create --title "Fix: corrected relative paths" \
--body "Fixed nav links in diary entries"
# Create PR and open in browser to finish editing
gh pr create --web
# List open PRs
gh pr list
# Check out a PR locally to review
gh pr checkout 42
# Merge a PR
gh pr merge 42 --squash
# View PR status (checks, reviews)
gh pr status
Create and manage issues without leaving the terminal.
# Create an issue
gh issue create --title "Add fzf integration to workflow" \
--body "See discussion in Day 20 diary"
# List open issues
gh issue list
# View a specific issue
gh issue view 17
# Close an issue
gh issue close 17 --comment "Fixed in commit abc123"
# List issues assigned to you
gh issue list --assignee @me
Trigger workflows and monitor runs without opening the browser.
# List workflows gh workflow list # Trigger a workflow manually gh workflow run deploy.yml # Watch a workflow run in real time gh run watch # List recent runs gh run list --limit 10 # View logs from a failed run gh run view --log-failed
Create releases and upload assets from the CLI — useful in deployment scripts.
# Create a release gh release create v1.2.0 \ --title "Release 1.2.0" \ --notes "Bug fixes and performance improvements" # Upload an asset to a release gh release upload v1.2.0 ./dist/app-linux-amd64 # List releases gh release list # Download release assets gh release download v1.2.0
Manage repository secrets for CI/CD pipelines without using the web UI.
# Set a repository secret gh secret set DEPLOY_KEY < ~/.ssh/deploy_key # List secrets (names only — values are never shown) gh secret list # Delete a secret gh secret delete OLD_SECRET
gh api gives you authenticated access to any GitHub API endpoint — if gh doesn't have a built-in command for something, the API does.
# Get repository info as JSON
gh api repos/owner/repo-name
# List all repos in an org
gh api orgs/my-org/repos --paginate \
| jq '.[].full_name'
# Get rate limit status
gh api rate_limit
# GraphQL query
gh api graphql -f query='
query {
viewer {
login
repositories(first: 5) {
nodes { name }
}
}
}'
gh is the delivery mechanism for AI-generated code changes. The pattern: AI tool makes the change, gh ships it to GitHub.
aider makes code changes with full git integration. gh creates the PR.
# aider makes changes and commits them automatically
aider --message "Fix the broken relative paths in nav links"
# gh creates the PR from the new commits
gh pr create --title "Fix: nav link relative paths" \
--body "AI-assisted fix via aider"
# Or combine into a one-liner after aider finishes
gh pr create --fill # uses commit message as PR title/body
Pipe gh output through fzf for interactive PR and issue selection.
# Interactively select and checkout a PR
gh pr list | fzf | awk '{print $1}' | xargs gh pr checkout
# Interactively select and view an issue
gh issue list | fzf | awk '{print $1}' | xargs gh issue view
# Interactively select a workflow to trigger
gh workflow list | fzf | awk '{print $1}' | xargs gh workflow run
gh outputs JSON with --json flag — jq processes it.
# List PRs as JSON and extract specific fields
gh pr list --json number,title,author,state \
| jq '.[] | "\(.number) \(.author.login) \(.title)"'
# Get all open issues with labels
gh issue list --json number,title,labels \
| jq '.[] | select(.labels[].name == "bug")'
# Count commits per author in last 30 days
gh api repos/owner/repo/commits \
--paginate \
| jq '[.[].commit.author.name] | group_by(.) | map({author: .[0], count: length})'
Add shortcuts for common operations:
# Create aliases gh alias set prc 'pr create --fill' gh alias set prl 'pr list' gh alias set prm 'pr merge --squash' gh alias set il 'issue list' gh alias set ic 'issue create' # List your aliases gh alias list
# Table output (default)
gh pr list
# JSON output — for scripting
gh pr list --json number,title,state
# Template output — custom formatting
gh pr list --template '{{range .}}{{.number}}: {{.title}}{{"\n"}}{{end}}'
# Switch between GitHub accounts gh auth switch # Use a specific account for one command GH_TOKEN=ghp_your_token gh pr list
| Aspect | Reality |
|---|---|
| Learning curve | Low-Medium — command structure is logical. The API subcommand takes more reading. |
| Daily value | High — if you use GitHub regularly, browser trips drop significantly. |
| Scripting/automation | Excellent — JSON output, token auth, and paginate flag make it script-friendly. |
| AI tool integration | Natural fit — pairs directly with aider, Copilot, and any AI tool that touches git. |
| Non-GitHub repos | GitHub only — GitLab and Gitea have their own CLIs (glab, tea). |
| Offline use | Requires connectivity — it's an API client, not a local tool. |
| Replaces | Browser for PR/issue/release management, manual API calls with curl |
| Doesn't replace | git itself — gh is a GitHub layer on top of git, not a replacement |