Gh Cli Ops
Overview
Use gh + git to manage GitHub repositories, automation, and releases with repeatable, safe workflows.
Quick start (context)
- Use the wrapper so commands are logged:
scripts/ghx auth status, scripts/ghx repo view, git status -sb.
- Identify the task category and use the matching section or the command map in
references/gh-command-map.md.
- Prefer JSON output (
--json ... --jq ...) for scripted reads; ask before destructive changes (delete, merge, release delete, secret overwrite).
- Review
references/auto-summary.md to adapt based on recent successes/failures.
Automation wrapper (required)
- Use
scripts/ghx for all gh commands to log outcomes to references/usage-log.jsonl.
- The wrapper auto-updates
references/auto-summary.md after each command to capture what worked or failed.
- If you must run
gh directly (e.g., debugging), run scripts/track_command.sh gh ... afterward with the same args.
Task map
See references/gh-command-map.md for a task-to-command mapping and safe defaults.
Workflows & runs
- Use
gh workflow list/view/run to inspect or trigger workflows. Ensure the workflow supports on: workflow_dispatch before running.
- Provide inputs via
-f/-F or --json when needed; confirm expected inputs from the workflow file.
- Use
gh run list/view/watch/rerun/download to monitor or re-run jobs; use gh run view --log/--log-failed for logs.
- For deploys, identify the deploy workflow and trigger it via
gh workflow run with the correct --ref and inputs.
- If
gh workflow run fails with HTTP 403 and Resource not accessible by integration, check for GITHUB_TOKEN or GH_TOKEN in the environment. Unset them or replace with a PAT that has workflow permissions, then retry.
- Quick fix for local shells:
GITHUB_TOKEN= gh workflow run "<workflow>" -f key=value (clears the env var for that command).
- In GitHub Actions, prefer
GH_TOKEN set to a PAT or GitHub App token when you need to trigger workflows; the default GITHUB_TOKEN can be too limited for dispatching other workflows.
Secrets & variables
- Use
gh secret for Actions/Dependabot/Codespaces secrets; use gh variable for Actions/Dependabot variables.
- Scope to repo/org/environment as needed; check
gh secret set --help and gh variable set --help for scope flags.
- Prefer stdin or
--body to avoid shell history; confirm overwrite and scope with the user.
Releases & tags
- Use
gh release list/view/create/download/delete.
- Prefer
--generate-notes for release notes when appropriate; confirm tag names and target commits.
Deployments & environments
- For deployment environments, use environment-scoped secrets/variables (
-e <env>).
- For deployment history or custom deploy APIs, use
gh api with --paginate and --jq as needed.
PRs, issues, and repo admin
- Use
gh pr and gh issue for everyday collaboration.
- Use
gh repo view/fork/clone/sync for repo operations.
- Keep git operations (branching, rebasing, pushing) explicit and separate from gh steps.
API & advanced
- Use
gh api for endpoints not covered by built-in commands.
- Capture JSON with
gh api ... --jq or --paginate for large lists.
Troubleshooting auth
Resource not accessible by integration usually means the CLI is using an integration token (often GITHUB_TOKEN) that cannot dispatch workflows. Prefer a PAT stored via gh auth login --with-token or set GH_TOKEN to a PAT with workflow permissions; avoid leaving GITHUB_TOKEN exported in local shells.
GH_TOKEN/GITHUB_TOKEN environment variables override stored gh auth. If you see unexpected 403s, unset them or replace with a PAT/GitHub App token that has Actions/workflow permissions before retrying.
Self-improving loop (automated + manual)
Automated (always on when using scripts/ghx):
- Command outcomes are logged to
references/usage-log.jsonl.
scripts/auto_improve.py updates references/auto-summary.md and can append repeatable learnings to references/gh-ops-notes.md.
Manual (when new patterns are discovered):
- Append new command patterns, flags, or pitfalls to
references/gh-ops-notes.md.
- If a command/flag is missing or changed, update
references/gh-command-map.md.
- Run
scripts/refresh_gh_reference.sh to refresh references/gh-help.md from the locally installed gh.
Resources
scripts/
scripts/ghx: wrapper that logs gh command outcomes and triggers auto-summary updates.
scripts/track_command.sh: logs command outcomes to references/usage-log.jsonl.
scripts/auto_improve.py: generates references/auto-summary.md and auto-notes.
scripts/refresh_gh_reference.sh: regenerate references/gh-help.md from local gh help output.
references/
references/gh-command-map.md: task-to-command map and safe defaults.
references/gh-help.md: auto-generated help snapshot from the local gh version.
references/gh-ops-notes.md: living notes for patterns, pitfalls, and team conventions.
references/auto-summary.md: auto-generated success/failure summary for recent commands.
references/usage-log.jsonl: append-only command log (redacted).
1---2name: gh-cli-ops3description: GitHub CLI (gh) operations for repos, PRs/issues, workflows/runs, secrets/variables, releases/tags, and deployment-related automation. Use when a request involves gh commands, GitHub Actions workflows/runs, secrets or variables, releases, deployments/environments, or coordinating git with GitHub.4metadata:5 source: https://skillmd.com/skills/aibot88/gh-cli-ops6---78# Gh Cli Ops910## Overview11Use gh + git to manage GitHub repositories, automation, and releases with repeatable, safe workflows.1213## Quick start (context)141. Use the wrapper so commands are logged: `scripts/ghx auth status`, `scripts/ghx repo view`, `git status -sb`.152. Identify the task category and use the matching section or the command map in `references/gh-command-map.md`.163. Prefer JSON output (`--json ... --jq ...`) for scripted reads; ask before destructive changes (delete, merge, release delete, secret overwrite).174. Review `references/auto-summary.md` to adapt based on recent successes/failures.1819## Automation wrapper (required)20- Use `scripts/ghx` for all gh commands to log outcomes to `references/usage-log.jsonl`.21- The wrapper auto-updates `references/auto-summary.md` after each command to capture what worked or failed.22- If you must run `gh` directly (e.g., debugging), run `scripts/track_command.sh gh ...` afterward with the same args.2324## Task map25See `references/gh-command-map.md` for a task-to-command mapping and safe defaults.2627## Workflows & runs28- Use `gh workflow list/view/run` to inspect or trigger workflows. Ensure the workflow supports `on: workflow_dispatch` before running.29- Provide inputs via `-f`/`-F` or `--json` when needed; confirm expected inputs from the workflow file.30- Use `gh run list/view/watch/rerun/download` to monitor or re-run jobs; use `gh run view --log/--log-failed` for logs.31- For deploys, identify the deploy workflow and trigger it via `gh workflow run` with the correct `--ref` and inputs.32- If `gh workflow run` fails with `HTTP 403` and `Resource not accessible by integration`, check for `GITHUB_TOKEN` or `GH_TOKEN` in the environment. Unset them or replace with a PAT that has workflow permissions, then retry.33- Quick fix for local shells: `GITHUB_TOKEN= gh workflow run "<workflow>" -f key=value` (clears the env var for that command).34- In GitHub Actions, prefer `GH_TOKEN` set to a PAT or GitHub App token when you need to trigger workflows; the default `GITHUB_TOKEN` can be too limited for dispatching other workflows.3536## Secrets & variables37- Use `gh secret` for Actions/Dependabot/Codespaces secrets; use `gh variable` for Actions/Dependabot variables.38- Scope to repo/org/environment as needed; check `gh secret set --help` and `gh variable set --help` for scope flags.39- Prefer stdin or `--body` to avoid shell history; confirm overwrite and scope with the user.4041## Releases & tags42- Use `gh release list/view/create/download/delete`.43- Prefer `--generate-notes` for release notes when appropriate; confirm tag names and target commits.4445## Deployments & environments46- For deployment environments, use environment-scoped secrets/variables (`-e <env>`).47- For deployment history or custom deploy APIs, use `gh api` with `--paginate` and `--jq` as needed.4849## PRs, issues, and repo admin50- Use `gh pr` and `gh issue` for everyday collaboration.51- Use `gh repo view/fork/clone/sync` for repo operations.52- Keep git operations (branching, rebasing, pushing) explicit and separate from gh steps.5354## API & advanced55- Use `gh api` for endpoints not covered by built-in commands.56- Capture JSON with `gh api ... --jq` or `--paginate` for large lists.5758## Troubleshooting auth59- `Resource not accessible by integration` usually means the CLI is using an integration token (often `GITHUB_TOKEN`) that cannot dispatch workflows. Prefer a PAT stored via `gh auth login --with-token` or set `GH_TOKEN` to a PAT with workflow permissions; avoid leaving `GITHUB_TOKEN` exported in local shells.60- `GH_TOKEN`/`GITHUB_TOKEN` environment variables override stored gh auth. If you see unexpected 403s, unset them or replace with a PAT/GitHub App token that has Actions/workflow permissions before retrying.6162## Self-improving loop (automated + manual)63Automated (always on when using `scripts/ghx`):641. Command outcomes are logged to `references/usage-log.jsonl`.652. `scripts/auto_improve.py` updates `references/auto-summary.md` and can append repeatable learnings to `references/gh-ops-notes.md`.6667Manual (when new patterns are discovered):681. Append new command patterns, flags, or pitfalls to `references/gh-ops-notes.md`.692. If a command/flag is missing or changed, update `references/gh-command-map.md`.703. Run `scripts/refresh_gh_reference.sh` to refresh `references/gh-help.md` from the locally installed `gh`.7172## Resources73### scripts/74- `scripts/ghx`: wrapper that logs gh command outcomes and triggers auto-summary updates.75- `scripts/track_command.sh`: logs command outcomes to `references/usage-log.jsonl`.76- `scripts/auto_improve.py`: generates `references/auto-summary.md` and auto-notes.77- `scripts/refresh_gh_reference.sh`: regenerate `references/gh-help.md` from local gh help output.7879### references/80- `references/gh-command-map.md`: task-to-command map and safe defaults.81- `references/gh-help.md`: auto-generated help snapshot from the local gh version.82- `references/gh-ops-notes.md`: living notes for patterns, pitfalls, and team conventions.83- `references/auto-summary.md`: auto-generated success/failure summary for recent commands.84- `references/usage-log.jsonl`: append-only command log (redacted).