GitHub CLI Workflow
Use this skill to ground GitHub work in the locally installed gh CLI instead of guessing command syntax or reaching for raw API calls too early.
Start by checking the exact command surface in the current environment:
command -v gh
gh --version
gh --help
Quick Start
- Verify authentication with
gh auth status. - Confirm repository targeting before acting with
git remote -v,gh repo set-default --view, or explicit-R OWNER/REPO. - Prefer read-only discovery commands first, then mutations only after the user clearly asks for them.
- Prefer
--jsonwith--jqor--templatewhen you need deterministic summaries or machine-readable output. - Check
gh <command> <subcommand> --helpbefore using uncommon flags or less-frequent subcommands.
Working Style
- Prefer explicit repository scoping with
-R OWNER/REPOwhen outside a cloned repo, when multiple remotes exist, or when there is any ambiguity. - Prefer
gh repo set-default OWNER/REPOorGH_REPO=OWNER/REPOfor repeated work against one repository. - Use
gh auth statusbefore assuming which account or token scope is active. - Summarize the planned mutation before running create, edit, close, merge, review, or delete commands unless the user already requested that exact action.
- Prefer
gh apionly when a higher-levelgh issue,gh pr,gh repo,gh workflow, orgh runcommand does not expose the needed operation cleanly. - Use
GH_PROMPT_DISABLED=1plus explicit flags when you need non-interactive behavior.
Common Workflows
Authenticate and inspect context
- Use
gh auth loginto add an account. - Use
gh auth switchwhen multiple accounts are configured. - Use
gh auth refresh -s <scope>when a command needs extra scopes such asproject. - Use
gh auth setup-gitwhen git operations should reuse GitHub CLI auth.
Target the right repository
- In a cloned repo,
ghusually infers the target from git remotes. - Outside a repo, or when inference is risky, pass
-R OWNER/REPO. - For repeated work in one checkout, use
gh repo set-default OWNER/REPO.
Inspect repositories, issues, and pull requests
- Use
gh repo view,gh issue list,gh issue view,gh pr list, andgh pr viewfor normal inspection. - Use
gh statusfor a cross-repository view of relevant pull requests, issues, and notifications. - Use
gh search repos,gh search issues, orgh search prswhen the target repository is not yet known.
Create and update issues and pull requests
- Use explicit flags such as
--title,--body,--body-file,--label,--assignee, and--reviewerto avoid interactive prompts. - Use
gh pr create --fillwhen the branch history has a clean title and body source, then override with--titleor--bodyif needed. - Use
gh pr review --approve,--comment, or--request-changesfor review state changes. - Mention
Fixes #123orCloses #123in PR bodies when the merge should close an issue.
Inspect workflows, runs, releases, and browser views
- Use
gh workflow listandgh run listorgh run viewto inspect GitHub Actions state. - Use
gh release listandgh release viewfor release work. - Use
gh browseor--webvariants to hand off to the browser when the web UI is faster or clearer.
Use structured output and API escape hatches
- Prefer
--jsonover scraping terminal tables. - Add
--jqfor lightweight filtering without requiring a separatejqinstall. - Use
--templatewhen you need concise tabular or custom text output. - Use
gh api repos/{owner}/{repo}/...for REST calls andgh api graphqlfor GraphQL queries. - Use
--paginateand--slurpwhen traversing large result sets.
Environment Notes
GH_TOKENorGITHUB_TOKENcan override stored auth forgithub.com.GH_HOSTselects a GitHub Enterprise host when needed.GH_REPOsets the default repository in[HOST/]OWNER/REPOform.GH_DEBUG=apiis useful when you need HTTP-level troubleshooting.GH_PROMPT_DISABLED=1disables interactive prompting for automation-oriented runs.
References
- Command patterns and examples:
references/commands.md