--- description: This skill should be used when the user needs to work with GitHub CLI (gh) for issues, pull requests, workflows, labels, or projects. Examples include "list open PRs", "check workflow status", "filter issues by label", "get PR details", "list failed workflows". --- # GitHub CLI (gh) Usage Guide Comprehensive guide for using the `gh` command line tool to work with GitHub issues, pull requests, workflows, labels, and projects. --- ## Table of Contents 1. [Issues](#issues) 2. [Pull Requests](#pull-requests) 3. [Workflows](#workflows) 4. [Labels](#labels) 5. [Projects](#projects) 6. [Common Patterns](#common-patterns) --- ## Issues ### Listing Issues **List all open issues:** ```bash gh issue list ``` **List all issues (including closed):** ```bash gh issue list --state all ``` **List only closed issues:** ```bash gh issue list --state closed ``` **Limit number of results:** ```bash gh issue list --limit 50 ``` ### Filtering Issues **Filter by assignee:** ```bash gh issue list --assignee @me gh issue list --assignee username gh issue list --assignee "" # unassigned issues ``` **Filter by author:** ```bash gh issue list --author username ``` **Filter by label:** ```bash gh issue list --label bug gh issue list --label "bug,help wanted" # multiple labels (AND logic) ``` **Filter by milestone:** ```bash gh issue list --milestone "v1.0" ``` **Search with query:** ```bash gh issue list --search "error in:title" gh issue list --search "is:open is:issue assignee:@me" ``` ### Issue Details **View issue details:** ```bash gh issue view 123 gh issue view 123 --web # open in browser ``` **View issue with comments:** ```bash gh issue view 123 --comments ``` **Get JSON output for scripting:** ```bash gh issue view 123 --json number,title,state,labels,assignees ``` ### Creating and Managing Issues #### Basic Issue Creation **Simple issue creation:** ```bash gh issue create --title "Bug report" --body "Description" gh issue create --title "Feature request" --label enhancement --assignee @me ``` **Interactive issue creation (recommended for detailed issues):** ```bash gh issue create # Opens editor for title and body # Prompts for labels, assignees, milestone, projects ``` **Create with multiple options:** ```bash gh issue create \ --title "Add user authentication" \ --body "Need to implement JWT-based auth for API security" \ --label "enhancement,security" \ --assignee @me \ --milestone "v2.0" \ --project "Backend Improvements" ``` #### Issue Creation Best Practices **1. Use Issue Templates** If your repository has issue templates, you can use them: ```bash # Interactive selection from available templates gh issue create # Use specific template gh issue create --template bug_report.md gh issue create --template feature_request.md ``` **2. Create Issue from File** For complex issues with detailed descriptions: ```bash # Create issue-body.md with your content gh issue create --title "Complex feature proposal" --body-file issue-body.md ``` Example `issue-body.md`: ```markdown ## Problem Statement Users cannot reset their passwords when logged out. ## Proposed Solution Add a "Forgot Password" flow with email verification. ## Implementation Details - Add password reset endpoint - Integrate with email service - Create reset token with 1-hour expiry ## Acceptance Criteria - [ ] User receives reset email within 1 minute - [ ] Token expires after 1 hour - [ ] User can set new password successfully ``` **3. Well-Structured Bug Reports** ```bash gh issue create --title "Login fails with valid credentials" --body "$(cat <<'EOF' ## Bug Description Users cannot log in even with correct username/password. ## Steps to Reproduce 1. Navigate to /login 2. Enter valid credentials 3. Click "Sign In" 4. Error: "Invalid credentials" ## Expected Behavior User should be logged in and redirected to dashboard. ## Actual Behavior Login fails with error message despite correct credentials. ## Environment - Browser: Chrome 120 - OS: macOS 14.1 - App version: 2.3.4 ## Additional Context Error appears in console: "TypeError: Cannot read property 'token' of undefined" ## Logs ``` [2024-01-15 10:23:45] POST /api/login 500 Internal Server Error ``` EOF )" --label bug --assignee @me ``` **4. Feature Requests with Context** ```bash gh issue create --title "Add dark mode support" --body "$(cat <<'EOF' ## Feature Description Add dark mode theme option to improve user experience in low-light environments. ## User Story As a user who works at night, I want a dark mode option so that I can reduce eye strain. ## Proposed Implementation - Add theme toggle in settings - Store preference in localStorage - Apply dark theme CSS variables - Support system preference detection ## Benefits - Reduced eye strain for users - Better battery life on OLED screens - Modern UX expectation ## Alternatives Considered - Browser extension (rejected: not all users can install extensions) - System theme only (rejected: users want manual control) ## References - [Material Design Dark Theme](https://material.io/design/color/dark-theme.html) - Similar feature in competitor apps EOF )" --label enhancement,ux --milestone "Q1 2024" ``` **5. Task/Chore Issues** ```bash gh issue create --title "Update dependencies to latest versions" --body "$(cat <<'EOF' ## Task Update all npm dependencies to resolve security vulnerabilities. ## Checklist - [ ] Update React to v18.2.0 - [ ] Update Express to v4.18.2 - [ ] Update testing libraries - [ ] Run full test suite - [ ] Update documentation ## Dependencies to Update - react: 17.0.2 → 18.2.0 - express: 4.17.1 → 4.18.2 - jest: 28.0.0 → 29.3.1 ## Security Notes 2 high-severity vulnerabilities will be resolved. EOF )" --label chore,security ``` #### Issue Creation Patterns **Pattern 1: Create Issue from Error Log** ```bash # Capture error and create issue ERROR_LOG=$(grep "ERROR" app.log | tail -20) gh issue create \ --title "Application errors in production" \ --body "$(cat < issues.json ``` ### Pattern 9: Find Recently Merged PRs ```bash gh pr list --state merged --limit 20 ``` ### Pattern 10: Get Workflow Run Logs for Debugging ```bash # View logs for specific run gh run view 123456 --log # Only failed job logs gh run view 123456 --log-failed # Download logs locally gh run download 123456 ``` --- ## Advanced Usage ### Using JQ with JSON Output The `gh` CLI supports `--json` and `--jq` for powerful filtering: **Get specific fields from PRs:** ```bash gh pr list --json number,title,author,labels --jq '.[] | select(.author.login == "username")' ``` **Find PRs with specific label:** ```bash gh pr list --json number,title,labels --jq '.[] | select(.labels[].name == "bug")' ``` **Count issues by label:** ```bash gh issue list --limit 1000 --json labels --jq '[.[].labels[].name] | group_by(.) | map({label: .[0], count: length})' ``` ### Using GitHub API Directly For operations not supported by `gh` subcommands: ```bash # GET request gh api repos/{owner}/{repo}/issues # POST request gh api repos/{owner}/{repo}/issues -f title="New issue" -f body="Description" # GraphQL gh api graphql -f query='query { viewer { login } }' ``` --- ## Best Practices 1. **Use `--json` for scripting**: When parsing output in scripts, always use `--json` for stable, parseable output 2. **Combine with `--jq`**: Filter JSON output using jq queries for precise data extraction 3. **Limit results**: Use `--limit` to avoid overwhelming output for large repositories 4. **Use search queries**: The `--search` flag supports GitHub's powerful search syntax 5. **Check authentication**: Ensure you're authenticated with `gh auth status` 6. **Use `--web` for detailed views**: When you need to interact with the UI, use `--web` to open in browser --- ## Troubleshooting **Check authentication status:** ```bash gh auth status ``` **Login/re-authenticate:** ```bash gh auth login ``` **Check gh version:** ```bash gh --version ``` **Enable debug output:** ```bash GH_DEBUG=1 gh pr list ``` **Get help for any command:** ```bash gh issue --help gh pr --help gh workflow --help ``` --- ## Reference Links - [GitHub CLI Manual](https://cli.github.com/manual/) - [GitHub Search Syntax](https://docs.github.com/en/search-github/searching-on-github) - [GitHub GraphQL API](https://docs.github.com/en/graphql) --- **Remember:** When using `gh` commands: - Always check authentication first - Use `--help` to explore available options - Combine with standard Unix tools (grep, awk, jq) for powerful workflows - Consider using `--json` with `--jq` for complex filtering - Use `--web` when you need the full GitHub UI experience