GitHub CLI (gh)
Concise guide to GitHub CLI for development workflows. Use --repo owner/repo when not in a git directory.
Installation & Setup
# Install
brew install gh # macOS
sudo apt install gh # Linux
# Authenticate
gh auth login
# Setup git integration
gh auth setup-git
Core Commands
Repository Operations
gh repo clone owner/repo
gh repo create my-repo --public/--private
gh repo view owner/repo
gh repo list --json name,description
Issues & Pull Requests
gh issue list --state open
gh issue create --title "Fix bug"
gh pr create --title "Add feature"
gh pr list --json number,title,author
gh pr checkout 123
CI/CD Workflows
gh run list --limit 5
gh run view <run-id> --log
gh workflow run ci.yml
API Access
gh api /user
gh api repos/owner/repo/issues --jq '.[].title'
Programmatic Usage
For apps/scripts, focus on JSON output and API endpoints:
# Get structured data
gh issue list --json number,title,state,labels --jq '.[] | select(.state == "open")'
# API queries for automation
gh api repos/owner/repo/pulls --jq '.[].head.ref'
# Batch operations
gh pr list --json number --jq '.[].number' | xargs -I {} gh pr edit {} --add-label ready
References
- Authentication: See
auth.mdfor enterprise setup and token management - Repository Management: See
repo-operations.mdfor advanced repo workflows - CI/CD Integration: See
ci-cd-automation.mdfor workflow automation - API Patterns: See
api-reference.mdfor programmatic usage examples - Common Scripts: See
examples.mdfor reusable automation patterns
Environment Variables
export GH_TOKEN=your_token # For automation
export GH_HOST=github.com # Default host
export GH_REPO=owner/repo # Default repository
export GH_PROMPT_DISABLED=true # Disable prompts
Quick Tips
- Use
--json+--jqfor structured data extraction - Use
--paginatefor large result sets - Use
--repo owner/repoto specify repository explicitly - Use
gh apifor advanced GitHub API access
Version: 2.85.0 (January 2026) Docs: https://cli.github.com/manual/