← GitHub articles

Reviewing pull requests and rerunning failed jobs through a browser takes longer than it should. The terminal can do both.

Triage and Ship from the Terminal: gh CLI for Platform Teams

How to use gh CLI to create issues, review and merge pull requests, and rerun workflows, with small scripts that keep the commands consistent.

Shubham Anandani··3 min read

Problem

Platform teams spend much of their day in a shell. The gh CLI covers many everyday GitHub operations: issues, pull requests, projects, releases, and workflow runs. In CI, the GH_TOKEN environment variable provides authentication. With a few scripts, triage and review stop depending on tab-switching.

Options and trade-offs

  • Pull requests: list, check out, review, and merge from the terminal. Fast, but comments need discipline.
  • Issues: create, list, assign, and comment. Templates can be applied through body files.
  • Workflows: run, watch, and rerun. Rerunning only failed jobs saves time.
  • gh api: reach any REST or GraphQL endpoint and filter the output with jq. Powerful, and easy to misuse without authentication.

My take

Write a short list of scripts for the actions you repeat most, keep them in the repository, and teach the team a small core set of commands before introducing anything more complex.

Decision lens: review latency and maintenance cost.

Example setup: three scripts for approving and squash-merging a pull request, rerunning failed jobs, and opening a bug issue from a template, each logging its output to a file for an audit trail.

Template

scripts/approve_and_squash.sh:

#!/usr/bin/env bash
set -euo pipefail
gh pr review "$1" --approve
gh pr merge "$1" --squash --delete-branch

scripts/rerun_failed.sh:

#!/usr/bin/env bash
set -euo pipefail
gh run rerun "$1" --failed
gh run watch "$1"

scripts/new_bug.sh:

#!/usr/bin/env bash
set -euo pipefail
gh issue create --title "$1" --body-file .github/ISSUE_TEMPLATE/bug.md --label bug --assignee @me

In CI, set GH_TOKEN so gh commands authenticate.

Checklist

  1. Install gh and run gh auth login.
  2. Set GH_TOKEN in any workflow that calls gh.
  3. Add scripts for pull request review and workflow reruns.
  4. Create issues from templates to keep them consistent.
  5. Log script output for audit trails.
  6. Teach a short list of core commands first.

Common mistakes

  • Missing GH_TOKEN in workflows, so gh calls fail.
  • Merging without deleting the branch, so stale branches pile up.
  • Rerunning an entire workflow when only the failed jobs need it.

Where this doesn't apply

  • Locked-down environments where the CLI is not available.

How to get involved

  • Good first issue: add a script that opens the logs for a failing run.
  • Discussion: which ten gh commands should new team members learn first?

Sources (accessed 2026-10-18)

  • Using GitHub CLI in workflows: https://docs.github.com/en/actions/using-workflows/using-github-cli-in-workflows. GH_TOKEN and examples.
  • gh pr checks manual: https://cli.github.com/manual/gh_pr_checks. Behavior and exit codes.

---