GitHub CLI (gh)
Comprehensive reference for GitHub CLI (gh) - work seamlessly with GitHub from the command line.
Version: 2.85.0 (current as of January 2026)
Prerequisites
Installation
brew 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 [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
winget install --id GitHub.cli
gh --version
Authentication
gh auth login
gh auth login --hostname enterprise.internal
gh auth login --with-token < mytoken.txt
gh auth status
gh auth switch --hostname github.com --user username
gh auth logout --hostname github.com --user username
Setup Git Integration
gh auth setup-git
gh auth token
gh auth refresh --scopes write:org,read:public_key
CLI Structure
gh # Root command
βββ auth # Authentication
β βββ login
β βββ logout
β βββ refresh
β βββ setup-git
β βββ status
β βββ switch
β βββ token
βββ browse # Open in browser
βββ codespace # GitHub Codespaces
β βββ code
β βββ cp
β βββ create
β βββ delete
β βββ edit
β βββ jupyter
β βββ list
β βββ logs
β βββ ports
β βββ rebuild
β βββ ssh
β βββ stop
β βββ view
βββ gist # Gists
β βββ clone
β βββ create
β βββ delete
β βββ edit
β βββ list
β βββ rename
β βββ view
βββ issue # Issues
β βββ create
β βββ list
β βββ status
β βββ close
β βββ comment
β βββ delete
β βββ develop
β βββ edit
β βββ lock
β βββ pin
β βββ reopen
β βββ transfer
β βββ unlock
β βββ view
βββ org # Organizations
β βββ list
βββ pr # Pull Requests
β βββ create
β βββ list
β βββ status
β βββ checkout
β βββ checks
β βββ close
β βββ comment
β βββ diff
β βββ edit
β βββ lock
β βββ merge
β βββ ready
β βββ reopen
β βββ revert
β βββ review
β βββ unlock
β βββ update-branch
β βββ view
βββ project # Projects
β βββ close
β βββ copy
β βββ create
β βββ delete
β βββ edit
β βββ field-create
β βββ field-delete
β βββ field-list
β βββ item-add
β βββ item-archive
β βββ item-create
β βββ item-delete
β βββ item-edit
β βββ item-list
β βββ link
β βββ list
β βββ mark-template
β βββ unlink
β βββ view
βββ release # Releases
β βββ create
β βββ list
β βββ delete
β βββ delete-asset
β βββ download
β βββ edit
β βββ upload
β βββ verify
β βββ verify-asset
β βββ view
βββ repo # Repositories
β βββ create
β βββ list
β βββ archive
β βββ autolink
β βββ clone
β βββ delete
β βββ deploy-key
β βββ edit
β βββ fork
β βββ gitignore
β βββ license
β βββ rename
β βββ set-default
β βββ sync
β βββ unarchive
β βββ view
βββ cache # Actions caches
β βββ delete
β βββ list
βββ run # Workflow runs
β βββ cancel
β βββ delete
β βββ download
β βββ list
β βββ rerun
β βββ view
β βββ watch
βββ workflow # Workflows
β βββ disable
β βββ enable
β βββ list
β βββ run
β βββ view
βββ agent-task # Agent tasks
βββ alias # Command aliases
β βββ delete
β βββ import
β βββ list
β βββ set
βββ api # API requests
βββ attestation # Artifact attestations
β βββ download
β βββ trusted-root
β βββ verify
βββ completion # Shell completion
βββ config # Configuration
β βββ clear-cache
β βββ get
β βββ list
β βββ set
βββ extension # Extensions
β βββ browse
β βββ create
β βββ exec
β βββ install
β βββ list
β βββ remove
β βββ search
β βββ upgrade
βββ gpg-key # GPG keys
β βββ add
β βββ delete
β βββ list
βββ label # Labels
β βββ clone
β βββ create
β βββ delete
β βββ edit
β βββ list
βββ preview # Preview features
βββ ruleset # Rulesets
β βββ check
β βββ list
β βββ view
βββ search # Search
β βββ code
β βββ commits
β βββ issues
β βββ prs
β βββ repos
βββ secret # Secrets
β βββ delete
β βββ list
β βββ set
βββ ssh-key # SSH keys
β βββ add
β βββ delete
β βββ list
βββ status # Status overview
βββ variable # Variables
βββ delete
βββ get
βββ list
βββ set
Configuration
Global Configuration
gh config list
gh config list git_protocol
gh config get editor
gh config set editor vim
gh config set git_protocol ssh
gh config set prompt disabled
gh config set pager "less -R"
gh config clear-cache
Environment Variables
export GH_TOKEN=ghp_xxxxxxxxxxxx
export GH_HOST=github.com
export GH_PROMPT_DISABLED=true
export GH_EDITOR=vim
export GH_PAGER=less
export GH_TIMEOUT=30
export GH_REPO=owner/repo
export GH_ENTERPRISE_HOSTNAME=hostname
Authentication (gh auth)
Login
gh auth login
gh auth login --web
gh auth login --web --clipboard
gh auth login --git-protocol ssh
gh auth login --hostname enterprise.internal
gh auth login --with-token < token.txt
gh auth login --insecure-storage
Status
gh auth status
gh auth status --active
gh auth status --hostname github.com
gh auth status --show-token
gh auth status --json hosts
gh auth status --json hosts --jq '.hosts | add'
Switch Accounts
gh auth switch
gh auth switch --hostname github.com --user monalisa
Token
gh auth token
gh auth token --hostname github.com --user monalisa
Refresh
gh auth refresh
gh auth refresh --scopes write:org,read:public_key
gh auth refresh --remove-scopes delete_repo
gh auth refresh --reset-scopes
gh auth refresh --clipboard
Setup Git
gh auth setup-git
gh auth