Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Use the gh CLI to interact with GitHub. Always specify --repo owner/repo when not in a git directory, or use URLs directly.
When helping with open-source contributions from a fork, default to a conservative flow:
For fork workflows, you MUST NOT run PR-mutating commands unless the user explicitly asks for that action in the current request.
gh pr creategh pr editgh pr mergegh apiBefore any approved PR action, state the exact source and target, for example:
myfork:feature-branchupstream:mainThen proceed only after explicit user confirmation.
Prepare contribution only (default):
Done: branch created, changes committed, pushed to fork.
Stopping here. If you want, I can create a PR to upstream next.
Create PR (only after explicit request):
gh pr create --repo upstream-owner/repo --head myfork:feature-branch --base main
Check CI status on a PR:
gh pr checks 55 --repo owner/repo
List recent workflow runs:
gh run list --repo owner/repo --limit 10
View a run and see which steps failed:
gh run view <run-id> --repo owner/repo
View logs for failed steps only:
gh run view <run-id> --repo owner/repo --log-failed
The gh api command is useful for accessing data not available through other subcommands.
Get PR with specific fields:
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'
Most commands support --json for structured output. You can use --jq to filter:
gh issue list --repo owner/repo --json number,title --jq '.[] | "\(.number): \(.title)"'