| name | github-cli |
| description | Comprehensive guide for using GitHub CLI (gh) to interact with GitHub from the command line. Use when (1) Managing GitHub repositories, issues, pull requests, or releases from terminal, (2) Automating GitHub workflows in scripts, (3) Creating or managing pull requests, (4) Working with GitHub issues, (5) Creating releases or managing repository operations, (6) Integrating GitHub operations into development workflows, (7) Using GitHub CLI commands in automation scripts |
| metadata | {"short-description":"GitHub CLI command reference and workflows"} |
GitHub CLI (gh)
GitHub CLI (gh) enables terminal-based interaction with GitHub for managing repositories, issues, pull requests, and releases.
Quick Start
Authentication:
gh auth login
gh auth status
Basic operations:
gh repo view
gh pr list
gh issue list
gh pr create
Core Workflows
Repository Operations
View repository:
gh repo view OWNER/REPO
gh repo view --web
Clone and create:
gh repo clone OWNER/REPO
gh repo create my-repo --public
gh repo create my-repo --private --clone
List repositories:
gh repo list
gh repo list USERNAME
gh repo list --limit 10
Pull Request Workflow
Create PR:
gh pr create
gh pr create --title "feat: feature" --body "description"
gh pr create --draft
gh pr create --base main --head feature-branch
Manage PRs:
gh pr list
gh pr view PR_NUMBER
gh pr checkout PR_NUMBER
gh pr merge PR_NUMBER
gh pr close PR_NUMBER
gh pr review PR_NUMBER --approve
PR status and diff:
gh pr checks PR_NUMBER
gh pr diff PR_NUMBER
gh pr view PR_NUMBER --web
Issue Management
Create and list:
gh issue create --title "Bug: title" --body "description"
gh issue list
gh issue list --state all
gh issue list --label "bug"
Manage issues:
gh issue view ISSUE_NUMBER
gh issue close ISSUE_NUMBER --comment "Fixed"
gh issue reopen ISSUE_NUMBER
gh issue edit ISSUE_NUMBER --title "New title"
Release Management
Create release:
gh release create v1.0.0 --title "v1.0.0" --notes "Release notes"
gh release create v1.0.0 --notes-file CHANGELOG.md
gh release create v1.0.0 --prerelease
gh release create v1.0.0 dist/*.zip
Manage releases:
gh release list
gh release view TAG_NAME
gh release download TAG_NAME
gh release delete TAG_NAME
Configuration
Set editor:
gh config set editor "code -w"
gh config set editor "vim"
Create aliases:
gh alias set prl "pr list"
gh alias set prd "pr create --draft"
gh alias set il "issue list"
gh alias list
Git credentials:
gh auth setup-git
Advanced Usage
JSON Output and Filtering
JSON output:
gh pr list --json number,title,author
gh repo view --json name,stargazerCount,url
gh issue view ISSUE_NUMBER --json title,body,comments
With jq filtering:
gh pr list --json number,title,author --jq '.[] | select(.author.login == "username")'
Automation Scripts
Create PR script:
#!/bin/bash
BRANCH=$(git branch --show-current)
gh pr create --title "feat: feature" --body "Description" --base main --head "$BRANCH"
Check PR status:
#!/bin/bash
STATUS=$(gh pr view $1 --json state --jq '.state')
echo "PR #$1 status: $STATUS"
Search
gh search repos "language:python stars:>1000"
gh search issues "is:open label:bug"
gh search code "function_name"
Common Patterns
Daily development:
git checkout -b feature/new-feature
git push -u origin feature/new-feature
gh pr create --title "feat: new feature" --body "Description"
git checkout main && git pull && git branch -d feature/new-feature
Review PR:
gh pr list
gh pr view PR_NUMBER
gh pr checkout PR_NUMBER
gh pr review PR_NUMBER --approve
Batch operations:
gh issue list --state open --json number --jq '.[].number' | xargs -I {} gh issue close {}
Troubleshooting
Authentication:
gh auth status
gh auth login
gh auth logout
Environment variables:
export GITHUB_TOKEN=your_token
$env:GITHUB_TOKEN="token"
References
For detailed command reference and advanced workflows, see: