|
| 1 | +--- |
| 2 | +name: gh-cli |
| 3 | +description: 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. |
| 4 | +--- |
| 5 | + |
| 6 | +# GitHub CLI (gh) |
| 7 | + |
| 8 | +Work seamlessly with GitHub from the command line. For the complete command reference see [`references/full-reference.md`](references/full-reference.md). |
| 9 | + |
| 10 | +## Authentication |
| 11 | + |
| 12 | +```bash |
| 13 | +# Interactive login |
| 14 | +gh auth login |
| 15 | + |
| 16 | +# Login with token |
| 17 | +gh auth login --with-token < token.txt |
| 18 | + |
| 19 | +# Check status |
| 20 | +gh auth status |
| 21 | + |
| 22 | +# Switch accounts |
| 23 | +gh auth switch --hostname github.com --user username |
| 24 | + |
| 25 | +# Setup git credential helper |
| 26 | +gh auth setup-git |
| 27 | + |
| 28 | +# Print active token |
| 29 | +gh auth token |
| 30 | +``` |
| 31 | + |
| 32 | +## Pull Requests |
| 33 | + |
| 34 | +```bash |
| 35 | +# Create PR (interactive) |
| 36 | +gh pr create |
| 37 | + |
| 38 | +# Create with title, body, base, draft, reviewer |
| 39 | +gh pr create --title "Feature: X" --body "Details..." --base main --draft --reviewer alice |
| 40 | + |
| 41 | +# List open PRs |
| 42 | +gh pr list |
| 43 | + |
| 44 | +# List with filters |
| 45 | +gh pr list --author @me --labels bug --state all --limit 50 |
| 46 | + |
| 47 | +# View a PR |
| 48 | +gh pr view 123 |
| 49 | +gh pr view 123 --comments --web |
| 50 | + |
| 51 | +# Merge a PR |
| 52 | +gh pr merge 123 --squash --delete-branch |
| 53 | + |
| 54 | +# Check CI status |
| 55 | +gh pr checks 123 |
| 56 | +gh pr checks 123 --watch |
| 57 | +``` |
| 58 | + |
| 59 | +## Issues |
| 60 | + |
| 61 | +```bash |
| 62 | +# Create issue (interactive) |
| 63 | +gh issue create |
| 64 | + |
| 65 | +# Create with title and labels |
| 66 | +gh issue create --title "Bug: X" --body "Steps..." --labels bug,high-priority --assignee @me |
| 67 | + |
| 68 | +# List open issues |
| 69 | +gh issue list |
| 70 | + |
| 71 | +# List with filters |
| 72 | +gh issue list --assignee @me --labels bug --state all --search "is:open label:bug" |
| 73 | + |
| 74 | +# View an issue |
| 75 | +gh issue view 123 |
| 76 | +gh issue view 123 --comments --web |
| 77 | + |
| 78 | +# Close / reopen |
| 79 | +gh issue close 123 --comment "Fixed in PR #456" |
| 80 | +gh issue reopen 123 |
| 81 | +``` |
| 82 | + |
| 83 | +## Common Flags |
| 84 | + |
| 85 | +| Flag | Description | |
| 86 | +|---|---| |
| 87 | +| `--repo OWNER/REPO` | Target a specific repository | |
| 88 | +| `--json FIELDS` | Output JSON for given fields | |
| 89 | +| `--jq EXPRESSION` | Filter JSON output with jq | |
| 90 | +| `--web` | Open result in browser | |
| 91 | +| `--paginate` | Follow pagination for large result sets | |
| 92 | +| `--limit N` | Cap result count | |
| 93 | + |
| 94 | +## API Requests |
| 95 | + |
| 96 | +```bash |
| 97 | +# REST GET |
| 98 | +gh api /user --jq '.login' |
| 99 | + |
| 100 | +# REST POST with fields |
| 101 | +gh api --method POST /repos/owner/repo/issues \ |
| 102 | + --field title="Issue title" --field body="Body" |
| 103 | + |
| 104 | +# Paginate all results |
| 105 | +gh api /user/repos --paginate |
| 106 | + |
| 107 | +# GraphQL query |
| 108 | +gh api graphql -f query='{ viewer { login } }' |
| 109 | +``` |
| 110 | + |
| 111 | +## JSON Output Examples |
| 112 | + |
| 113 | +```bash |
| 114 | +# List PR numbers and titles |
| 115 | +gh pr list --json number,title --jq '.[] | "\(.number): \(.title)"' |
| 116 | + |
| 117 | +# Get issue labels |
| 118 | +gh issue view 123 --json labels --jq '.labels[].name' |
| 119 | + |
| 120 | +# Filter open PRs by author |
| 121 | +gh pr list --json number,title,author \ |
| 122 | + --jq '.[] | select(.author.login == "alice")' |
| 123 | +``` |
| 124 | + |
| 125 | +## Complete Reference |
| 126 | + |
| 127 | +For all commands including repos, releases, Actions, projects, gists, codespaces, search, secrets, extensions, and more, see: |
| 128 | + |
| 129 | +**[`references/full-reference.md`](references/full-reference.md)** |
0 commit comments