GitHub CLI gh: pull requests, issues, releases, Actions and the API
Use the gh CLI to open and merge pull requests, triage issues, cut releases, watch and rerun workflow runs, and call the GitHub REST/GraphQL API with jq filters.
Install in Claude Code
Put the file in a folder named after the skill inside Claude Code's skills folder, then start a new session. This command does it:
bash
mkdir -p ~/.claude/skills/github-cli && \
curl -fsSL https://md2.dev/library/raw/github-cli.md \
-o ~/.claude/skills/github-cli/SKILL.md Preview
GitHub CLI (gh)
When to use
Any GitHub task that has a command: pull requests, issues, releases, Actions, repo settings, API queries. Prefer gh to scraping web pages.
Prerequisites
BASH
gh --version
gh auth status # logged in? else: gh auth login
gh auth refresh -s workflow # add a missing scope
# CI: export GH_TOKEN=<token> # no interactive login neededRun inside a clone: gh infers the repository from the git remote, or pass -R owner/repo.
Pull request workflow
- Push the branch:
git push -u origin HEAD. - Open the PR with a real title and body.
- Watch checks, address review comments, then merge.
BASH
gh pr create --base main --title "feat(export): add EPUB" --body-file pr.md
gh pr create --fill --draft # title and body from commits
gh pr list --author @me --state open
gh pr view 42 --comments
gh pr diff 42 --name-only
gh pr checkout 42
gh pr checks 42 --watch # block until CI finishes
gh pr review 42 --approve --body "LGTM"
gh pr review 42 --request-changes --body "see inline"
gh pr merge 42 --squash --delete-branch # add --auto to wait for checks
gh pr ready 42 # draft to readyIssues
BASH
gh issue create --title "Tables overflow in RTL" --body "Steps: ..." --label bug
gh issue list --label bug --assignee @me --json number,title --jq '.[] | "\(.number) \(.title)"'
gh issue comment 17 --body "Fixed in #42"
gh issue close 17 --reason completedReleases
BASH
git tag -a v1.4.0 -m "v1.4.0" && git push origin v1.4.0
gh release create v1.4.0 --generate-notes --latest ./dist/app.zip ./dist/app.tar.gz
gh release upload v1.4.0 ./dist/extra.zip --clobber
gh release list --limit 5
gh release download v1.4.0 --pattern "*.zip"Actions
BASH
gh run list --workflow ci.yml --limit 5
gh run view <run-id> --log-failed # only the failing steps
gh run watch <run-id> --exit-status # non-zero exit if the run fails
gh run rerun <run-id> --failed
gh workflow run deploy.yml -f environment=staging
gh workflow listAPI
{owner} and {repo} are filled from the current repository.
BASH
gh api repos/{owner}/{repo}/pulls/42/comments --paginate --jq '.[] | {user: .user.login, body}'
gh api -X POST repos/{owner}/{repo}/issues -f title="Bug" -f body="Details"
gh api repos/{owner}/{repo}/branches/main/protection
gh api graphql -f query='query { viewer { login } }'
gh api --cache 1h repos/{owner}/{repo}/releases/latest --jq .tag_nameRepository
BASH
gh repo clone owner/repo
gh repo create my-app --private --source . --push
gh repo view --web
gh search issues "is:open label:bug repo:owner/repo" --json number,titleGotchas
gh pr mergewith no flag asks questions in a terminal; always pass--squash,--mergeor--rebasein scripts.- Use
--body-filefor long bodies so shell quoting cannot mangle them. --jsonneeds explicit field names (run it with an invalid field to list them); combine with--jqinstead of piping tojq.gh run watchpolls; add--interval 10to be gentle on rate limits.- Pushing workflow files needs the
workflowtoken scope. - Never print tokens:
gh auth tokenis for piping only.
Verify
BASH
gh pr view --json state,mergeable,statusCheckRollup --jq '{state, mergeable}'
gh pr checks # all green before merging
gh release view v1.4.0 --json assets --jq '.assets[].name'