This chapter covers the remaining gh commands that don't fit neatly into earlier chapters but are still valuable.

gh browse — Open in the Browser

Quickly open the current repository (or specific pages) in your web browser.

# Open the repo homepage
gh browse
 
# Open a specific file
gh browse src/main.go
 
# Open a file at a specific line
gh browse src/main.go:42
 
# Open a specific branch
gh browse --branch develop
 
# Open specific pages
gh browse --settings
gh browse --wiki
gh browse --projects
 
# Open a different repo
gh browse -R cli/cli
 
# Print the URL without opening
gh browse --no-browser

gh status — Your GitHub Dashboard

See a cross-repository summary of everything relevant to you.

gh status

Shows:

  • PRs assigned to you or requesting your review
  • Issues assigned to you
  • Mentions
  • Repository activity notifications
# Exclude a specific org
gh status --exclude my-org
 
# Limit to a specific org
gh status --org my-org

Labels (gh label)

Manage issue and PR labels.

Listing Labels

gh label list
 
# JSON output
gh label list --json name,color,description
 
# Sort
gh label list --sort name

Creating Labels

gh label create "priority: high" --color FF0000 --description "Urgent issues"
gh label create "type: feature" --color 0E8A16

Editing Labels

gh label edit "bug" --name "type: bug" --color CC0000
gh label edit "enhancement" --description "New feature request"

Deleting Labels

gh label delete "wontfix" --yes

Cloning Labels from Another Repo

Copy all labels from one repository to another:

gh label clone source-owner/source-repo
gh label clone source-owner/source-repo --force   # Overwrite existing

SSH Keys (gh ssh-key)

Manage SSH keys on your GitHub account.

# List your SSH keys
gh ssh-key list
 
# Add a key
gh ssh-key add ~/.ssh/id_ed25519.pub --title "My Laptop"
 
# Add a signing key
gh ssh-key add ~/.ssh/id_ed25519.pub --title "Signing Key" --type signing
 
# Delete a key
gh ssh-key delete <key-id> --yes

GPG Keys (gh gpg-key)

Manage GPG keys for commit signature verification.

# List your GPG keys
gh gpg-key list
 
# Add a key
gpg --armor --export YOUR_KEY_ID | gh gpg-key add
 
# Delete a key
gh gpg-key delete <key-id> --yes

Organizations (gh org)

# List organizations you belong to
gh org list
 
# Limit
gh org list --limit 50

Rulesets (gh ruleset)

Repository rulesets enforce branch protection and other rules.

Listing Rulesets

gh ruleset list
 
# Include rulesets inherited from the org
gh ruleset list --include-parents
 
# For a specific organization
gh ruleset list --org my-org

Viewing a Ruleset

gh ruleset view <ruleset-id>
gh ruleset view <ruleset-id> --web

Checking Rules Against a Branch

gh ruleset check main
gh ruleset check feature-branch

Attestations (gh attestation)

Artifact attestations provide cryptographic proof of where and how software artifacts were built.

Verifying an Artifact

Validates that an artifact was built from the expected source in the expected CI environment, using SLSA provenance:

gh attestation verify ./my-binary -R owner/repo
 
# Verify with a specific signer
gh attestation verify ./my-binary -R owner/repo --signer-repo owner/repo
 
# Verify an OCI container image
gh attestation verify oci://ghcr.io/owner/image:tag --owner owner
 
# Deny self-hosted runner builds
gh attestation verify ./my-binary -R owner/repo --deny-self-hosted-runners
 
# JSON output for automation
gh attestation verify ./my-binary -R owner/repo --format json

Downloading Attestation Bundles

Download Sigstore attestation bundles for offline verification:

gh attestation download ./my-binary -R owner/repo
 
# Download with a specific digest algorithm
gh attestation download ./my-binary -R owner/repo --digest-alg sha512

Trusted Root

Output the trusted_root.jsonl file used for offline verification:

gh attestation trusted-root
 
# For offline/air-gapped environments
gh attestation trusted-root --tuf-url <mirror-url> --tuf-root <file-path>
 
# Verify existing trusted root only
gh attestation trusted-root --verify-only

Copilot (gh copilot)

If the GitHub Copilot extension is installed:

# Ask Copilot to explain a command
gh copilot explain "git rebase -i HEAD~3"
 
# Ask Copilot to suggest a command
gh copilot suggest "find all .log files larger than 100MB"

Install via:

gh extension install github/gh-copilot

Shell Completions (gh completion)

Generate completion scripts for your shell:

# Bash
gh completion -s bash > /etc/bash_completion.d/gh
 
# Zsh
gh completion -s zsh > "${fpath[1]}/_gh"
 
# Fish
gh completion -s fish > ~/.config/fish/completions/gh.fish
 
# PowerShell
gh completion -s powershell > gh.ps1

After installing, restart your shell or source the completion file.

Agent Tasks (gh agent-task) — Preview

GitHub's AI-powered coding agent can be managed from the CLI:

# Create a task for the agent
gh agent-task create "Fix the failing test in auth module"
gh agent-task create --from-file task-description.md
 
# Create a task targeting a specific base branch
gh agent-task create "Refactor login flow" --base develop
 
# Follow the task in real time
gh agent-task create "Add input validation" --follow
 
# List recent agent tasks
gh agent-task list
gh agent-task list --limit 10
 
# View a specific task
gh agent-task view <session-id>
gh agent-task view <session-id> --log
gh agent-task view <session-id> --web
 
# View by PR number or branch
gh agent-task view 42
gh agent-task view feature-branch

Note: This is a preview feature and may change.

MinTTY Support (Windows)

MinTTY, the default terminal for Git for Windows, has known issues with gh's interactive prompts.

Workarounds:

  1. Reinstall Git for Windows with "Enable experimental support for pseudo consoles" checked
  2. Use Windows Terminal running C:\Program Files\Git\bin\bash.exe
  3. Prefix commands with winpty:
    winpty gh auth login

Exercises

  1. Open the current repo in the browser: gh browse
  2. Check your status: gh status
  3. List labels: gh label list
  4. List your SSH keys: gh ssh-key list
  5. Generate completions: gh completion -s zsh (or your shell)