GitHub CLI (gh) comprehensive reference for repositories, issues, pull requests, Actions, projects, releases, gists, codespaces, organizations, extensions, and all GitHub operations from the command line.
Quick Install
bunx add-skill github/awesome-copilot -s gh-cli
aigithub-copilothacktoberfestprompt-engineering
Instructions
Loadingβ¦
GitHub CLI (gh)
Comprehensive reference for GitHub CLI (gh) - work seamlessly with GitHub from the command line.
# List all configuration
gh config list
# Get specific configuration value
gh config list git_protocol
gh config get editor
# Set configuration value
gh config set editor vim
gh config set git_protocol ssh
gh config set prompt disabled
gh config set pager "less -R"
# Clear configuration cache
gh config clear-cache
# Interactive login
gh auth login
# Web-based authentication
gh auth login --web
# With clipboard for OAuth code
gh auth login --web --clipboard
# With specific git protocol
gh auth login --git-protocol ssh
# With custom hostname (GitHub Enterprise)
gh auth login --hostname enterprise.internal
# Login with token from stdin
gh auth login --with-token < token.txt
# Insecure storage (plain text)
gh auth login --insecure-storage
Status
# Show all authentication status
gh auth status
# Show active account only
gh auth status --active
# Show specific hostname
gh auth status --hostname github.com
# Show token in output
gh auth status --show-token
# JSON output
gh auth status --json hosts
# Filter with jq
gh auth status --json hosts --jq '.hosts | add'
Switch Accounts
# Interactive switch
gh auth switch
# Switch to specific user/host
gh auth switch --hostname github.com --user monalisa
Token
# Print authentication token
gh auth token
# Token for specific host/user
gh auth token --hostname github.com --user monalisa
# Setup git credential helper
gh auth setup-git
# Setup for specific host
gh auth setup-git --hostname enterprise.internal
# Force setup even if host not known
gh auth setup-git --hostname enterprise.internal --force
Browse (gh browse)
# Open repository in browser
gh browse
# Open specific path
gh browse script/
gh browse main.go:312
# Open issue or PR
gh browse 123
# Open commit
gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
# Open with specific branch
gh browse main.go --branch bug-fix
# Open different repository
gh browse --repo owner/repo
# Open specific pages
gh browse --actions # Actions tab
gh browse --projects # Projects tab
gh browse --releases # Releases tab
gh browse --settings # Settings page
gh browse --wiki # Wiki page
# Print URL instead of opening
gh browse --no-browser
Repositories (gh repo)
Create Repository
# Create new repository
gh repo create my-repo
# Create with description
gh repo create my-repo --description "My awesome project"
# Create public repository
gh repo create my-repo --public
# Create private repository
gh repo create my-repo --private
# Create with homepage
gh repo create my-repo --homepage https://example.com
# Create with license
gh repo create my-repo --license mit
# Create with gitignore
gh repo create my-repo --gitignore python
# Initialize as template repository
gh repo create my-repo --template
# Create repository in organization
gh repo create org/my-repo
# Create without cloning locally
gh repo create my-repo --source=.
# Disable issues
gh repo create my-repo --disable-issues
# Disable wiki
gh repo create my-repo --disable-wiki
Clone Repository
# Clone repository
gh repo clone owner/repo
# Clone to specific directory
gh repo clone owner/repo my-directory
# Clone with different branch
gh repo clone owner/repo --branch develop
List Repositories
# List all repositories
gh repo list
# List repositories for owner
gh repo list owner
# Limit results
gh repo list --limit 50
# Public repositories only
gh repo list --public
# Source repositories only (not forks)
gh repo list --source
# JSON output
gh repo list --json name,visibility,owner
# Table output
gh repo list --limit 100 | tail -n +2
# Filter with jq
gh repo list --json name --jq '.[].name'
# View gitignore template
gh repo gitignore
# View license template
gh repo license mit
# License with full name
gh repo license mit --fullname "John Doe"
Issues (gh issue)
Create Issue
# Create issue interactively
gh issue create
# Create with title
gh issue create --title "Bug: Login not working"
# Create with title and body
gh issue create \
--title "Bug: Login not working" \
--body "Steps to reproduce..."
# Create with body from file
gh issue create --body-file issue.md
# Create with labels
gh issue create --title "Fix bug" --labels bug,high-priority
# Create with assignees
gh issue create --title "Fix bug" --assignee user1,user2
# Create in specific repository
gh issue create --repo owner/repo --title "Issue title"
# Create issue from web
gh issue create --web
List Issues
# List all open issues
gh issue list
# List all issues (including closed)
gh issue list --state all
# List closed issues
gh issue list --state closed
# Limit results
gh issue list --limit 50
# Filter by assignee
gh issue list --assignee username
gh issue list --assignee @me
# Filter by labels
gh issue list --labels bug,enhancement
# Filter by milestone
gh issue list --milestone "v1.0"
# Search/filter
gh issue list --search "is:open is:issue label:bug"
# JSON output
gh issue list --json number,title,state,author
# Table view
gh issue list --json number,title,labels --jq '.[] | [.number, .title, .labels[].name] | @tsv'
# Show comments count
gh issue list --json number,title,comments --jq '.[] | [.number, .title, .comments]'
# Sort by
gh issue list --sort created --order desc
# Create draft PR from issue
gh issue develop 123
# Create in specific branch
gh issue develop 123 --branch fix/issue-123
# Create with base branch
gh issue develop 123 --base main
Pull Requests (gh pr)
Create Pull Request
# Create PR interactively
gh pr create
# Create with title
gh pr create --title "Feature: Add new functionality"
# Create with title and body
gh pr create \
--title "Feature: Add new functionality" \
--body "This PR adds..."
# Fill body from template
gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md
# Set base branch
gh pr create --base main
# Set head branch (default: current branch)
gh pr create --head feature-branch
# Create draft PR
gh pr create --draft
# Add assignees
gh pr create --assignee user1,user2
# Add reviewers
gh pr create --reviewer user1,user2
# Add labels
gh pr create --labels enhancement,feature
# Link to issue
gh pr create --issue 123
# Create in specific repository
gh pr create --repo owner/repo
# Open in browser after creation
gh pr create --web
List Pull Requests
# List open PRs
gh pr list
# List all PRs
gh pr list --state all
# List merged PRs
gh pr list --state merged
# List closed (not merged) PRs
gh pr list --state closed
# Filter by head branch
gh pr list --head feature-branch
# Filter by base branch
gh pr list --base main
# Filter by author
gh pr list --author username
gh pr list --author @me
# Filter by assignee
gh pr list --assignee username
# Filter by labels
gh pr list --labels bug,enhancement
# Limit results
gh pr list --limit 50
# Search
gh pr list --search "is:open is:pr label:review-required"
# JSON output
gh pr list --json number,title,state,author,headRefName
# Show check status
gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'
# Sort by
gh pr list --sort created --order desc
# Revert merged PR
gh pr revert 123
# Revert with specific branch name
gh pr revert 123 --branch revert-pr-123
Pull Request Status
# Show PR status summary
gh pr status
# Status for specific repository
gh pr status --repo owner/repo
GitHub Actions
Workflow Runs (gh run)
# List workflow runs
gh run list
# List for specific workflow
gh run list --workflow "ci.yml"
# List for specific branch
gh run list --branch main
# Limit results
gh run list --limit 20
# JSON output
gh run list --json databaseId,status,conclusion,headBranch
# View run details
gh run view 123456789
# View run with verbose logs
gh run view 123456789 --log
# View specific job
gh run view 123456789 --job 987654321
# View in browser
gh run view 123456789 --web
# Watch run in real-time
gh run watch 123456789
# Watch with interval
gh run watch 123456789 --interval 5
# Rerun failed run
gh run rerun 123456789
# Rerun specific job
gh run rerun 123456789 --job 987654321
# Cancel run
gh run cancel 123456789
# Delete run
gh run delete 123456789
# Download run artifacts
gh run download 123456789
# Download specific artifact
gh run download 123456789 --name build
# Download to directory
gh run download 123456789 --dir ./artifacts
Workflows (gh workflow)
# List workflows
gh workflow list
# View workflow details
gh workflow view ci.yml
# View workflow YAML
gh workflow view ci.yml --yaml
# View in browser
gh workflow view ci.yml --web
# Enable workflow
gh workflow enable ci.yml
# Disable workflow
gh workflow disable ci.yml
# Run workflow manually
gh workflow run ci.yml
# Run with inputs
gh workflow run ci.yml \
--raw-field \
version="1.0.0" \
environment="production"
# Run from specific branch
gh workflow run ci.yml --ref develop
Action Caches (gh cache)
# List caches
gh cache list
# List for specific branch
gh cache list --branch main
# List with limit
gh cache list --limit 50
# Delete cache
gh cache delete 123456789
# Delete all caches
gh cache delete --all
Action Secrets (gh secret)
# List secrets
gh secret list
# Set secret (prompts for value)
gh secret set MY_SECRET
# Set secret from environment
echo "$MY_SECRET" | gh secret set MY_SECRET
# Set secret for specific environment
gh secret set MY_SECRET --env production
# Set secret for organization
gh secret set MY_SECRET --org orgname
# Delete secret
gh secret delete MY_SECRET
# Delete from environment
gh secret delete MY_SECRET --env production
Action Variables (gh variable)
# List variables
gh variable list
# Set variable
gh variable set MY_VAR "some-value"
# Set variable for environment
gh variable set MY_VAR "value" --env production
# Set variable for organization
gh variable set MY_VAR "value" --org orgname
# Get variable value
gh variable get MY_VAR
# Delete variable
gh variable delete MY_VAR
# Delete from environment
gh variable delete MY_VAR --env production
# List codespaces
gh codespace list
# Create codespace
gh codespace create
# Create with specific repository
gh codespace create --repo owner/repo
# Create with branch
gh codespace create --branch develop
# Create with specific machine
gh codespace create --machine premiumLinux
# View codespace details
gh codespace view
# SSH into codespace
gh codespace ssh
# SSH with specific command
gh codespace ssh --command "cd /workspaces && ls"
# Open codespace in browser
gh codespace code
# Open in VS Code
gh codespace code --codec
# Open with specific path
gh codespace code --path /workspaces/repo
# Stop codespace
gh codespace stop
# Delete codespace
gh codespace delete
# View logs
gh codespace logs
--tail 100
# View ports
gh codespace ports
# Forward port
gh codespace cp 8080:8080
# Rebuild codespace
gh codespace rebuild
# Edit codespace
gh codespace edit --machine standardLinux
# Jupyter support
gh codespace jupyter
# Copy files to/from codespace
gh codespace cp file.txt :/workspaces/file.txt
gh codespace cp :/workspaces/file.txt ./file.txt
Organizations (gh org)
# List organizations
gh org list
# List for user
gh org list --user username
# JSON output
gh org list --json login,name,description
# View organization
gh org view orgname
# View organization members
gh org view orgname --json members --jq '.members[] | .login'
# List labels
gh label list
# Create label
gh label create bug --color "d73a4a" --description "Something isn't working"
# Create with hex color
gh label create enhancement --color "#a2eeef"
# Edit label
gh label edit bug --name "bug-report" --color "ff0000"
# Delete label
gh label delete bug
# Clone labels from repository
gh label clone owner/repo
# Clone to specific repository
gh label clone owner/repo --repo target/repo
SSH Keys (gh ssh-key)
# List SSH keys
gh ssh-key list
# Add SSH key
gh ssh-key add ~/.ssh/id_rsa.pub --title "My laptop"
# Add key with type
gh ssh-key add ~/.ssh/id_ed25519.pub --type "authentication"
# Delete SSH key
gh ssh-key delete 12345
# Delete by title
gh ssh-key delete --title "My laptop"
GPG Keys (gh gpg-key)
# List GPG keys
gh gpg-key list
# Add GPG key
gh gpg-key add ~/.ssh/id_rsa.pub
# Delete GPG key
gh gpg-key delete 12345
# Delete by key ID
gh gpg-key delete ABCD1234
Status (gh status)
# Show status overview
gh status
# Status for specific repositories
gh status --repo owner/repo
# JSON output
gh status --json
Configuration (gh config)
# List all config
gh config list
# Get specific value
gh config get editor
# Set value
gh config set editor vim
# Set git protocol
gh config set git_protocol ssh
# Clear cache
gh config clear-cache
# Set prompt behavior
gh config set prompt disabled
gh config set prompt enabled
# List aliases
gh alias list
# Set alias
gh alias set prview 'pr view --web'
# Set shell alias
gh alias set co 'pr checkout' --shell
# Delete alias
gh alias delete prview
# Import aliases
gh alias import ./aliases.sh
API Requests (gh api)
# Make API request
gh api /user
# Request with method
gh api --method POST /repos/owner/repo/issues \
--field title="Issue title" \
--field body="Issue body"
# Request with headers
gh api /user \
--header "Accept: application/vnd.github.v3+json"
# Request with pagination
gh api /user/repos --paginate
# Raw output (no formatting)
gh api /user --raw
# Include headers in output
gh api /user --include
# Silent mode (no progress output)
gh api /user --silent
# Input from file
gh api --input request.json
# jq query on response
gh api /user --jq '.login'
# Field from response
gh api /repos/owner/repo --jq '.stargazers_count'
# GitHub Enterprise
gh api /user --hostname enterprise.internal
# GraphQL query
gh api graphql \
-f query='
{
viewer {
login
repositories(first: 5) {
nodes {
name
}
}
}
}'
Rulesets (gh ruleset)
# List rulesets
gh ruleset list
# View ruleset
gh ruleset view 123
# Check ruleset
gh ruleset check --branch feature
# Check specific repository
gh ruleset check --repo owner/repo --branch main
# Run workflow and wait
RUN_ID=$(gh workflow run ci.yml --ref main --jq '.databaseId')
# Watch the run
gh run watch "$RUN_ID"
# Download artifacts on completion
gh run download "$RUN_ID" --dir ./artifacts
# Add to ~/.bashrc or ~/.zshrc
eval "$(gh completion -s bash)" # or zsh/fish
# Create useful aliases
alias gs='gh status'
alias gpr='gh pr view --web'
alias gir='gh issue view --web'
alias gco='gh pr checkout'
Git Configuration
# Use gh as credential helper
gh auth setup-git
# Set gh as default for repo operations
git config --global credential.helper 'gh !gh auth setup-git'
# Or manually
git config --global credential.helper github
Best Practices
Authentication: Use environment variables for automation
export GH_TOKEN=$(gh auth token)
Default Repository: Set default to avoid repetition
Caching: Use cache control for frequently accessed data
gh api /user --cache force
Getting Help
# General help
gh --help
# Command help
gh pr --help
gh issue create --help
# Help topics
gh help formatting
gh help environment
gh help exit-codes
gh help accessibility