GitHub CLI — The Deployment That Succeeded via Wrong Workflow
A developer used the GitHub web UI to trigger a workflow.
20+ years shipping production infrastructure and CI/CD at scale. Notes here come from systems that actually shipped.
- ✓Solid grasp of devops fundamentals
- ✓Comfortable reading and writing code examples independently
- ✓Basic understanding of production deployment concepts
Install: brew install gh or apt install gh. Authenticate: gh auth login. Key commands: gh pr create, gh pr review, gh run list, gh issue create, gh repo clone.
GitHub CLI is the remote control for GitHub. Instead of clicking buttons on a website, you type commands in your terminal. Create a PR without opening a browser. Merge without leaving the editor. Run a deploy workflow with a single command. It's faster, scriptable, and harder to misclick than the web UI.
The GitHub web UI is designed for casual use. For daily operations — creating PRs, reviewing code, running workflows, managing issues — the CLI is faster and safer. A single gh pr create --fill creates a PR from your current branch without touching the mouse. gh workflow run deploy.yml --ref main triggers a deployment with a specific ref — no risk of clicking the wrong button. This guide covers the essential gh commands, the incident where web UI clicking triggered the wrong workflow, and how to script common operations.
Essential GitHub CLI Commands
Authentication: gh auth login (supports SSH, HTTPS, GitHub App tokens). Once authenticated, all commands work without tokens in environment variables.
PR workflow: gh pr create --fill (auto-fills from commits), gh pr view --web (open in browser), gh pr checkout <number> (fetch PR locally), gh pr merge --squash (merge without web UI).
Actions: gh run list --limit 5, gh run watch <id> (watch in terminal), gh run cancel <id>, gh workflow run deploy.yml --ref main -f env=production.
Issues: gh issue create --label bug, gh issue list --assignee @me, gh issue close <number>.
Releases: gh release create v1.0.0 --notes-from-tag, gh release list --limit 5.
gh alias set prd 'pr create --fill --assignee @me' creates a shortcut. Now gh prd creates a PR with auto-filled content. Share aliases via a .gh_aliases file in your repo's .github directory.github.event.triggering_actor == 'CLI' or validate that github.event.inputs.confirm == 'PRODUCTION'. Use GitHub Actions environment protection rules that require a specific number of approvals for production. CLI-based deploys reduce UI misclicks and leave an audit trail.gh) manages GitHub from the terminal. Safer than web UI for critical operations. Use gh pr create --fill for fast PR creation. Use gh workflow run with explicit parameters for deploys. Add confirmation inputs to production workflows.The 'Run Workflow' Button That Deployed Staging to Production
gh run list --workflow=deploy.yml then gh run cancel <id>. 2. Updated the deploy workflow to require a confirmation input: workflow_dispatch: inputs: confirm: description: 'Type PRODUCTION to confirm'. 3. Switched team to CLI-only deploys: gh workflow run deploy.yml --ref main -f env=production. 4. Added environment protection rules on GitHub requiring manual approval for production deployments.- GitHub web UI makes it easy to click the wrong workflow.
- Use CLI for critical operations — it forces explicit parameters.
- Add confirmation inputs to workflow_dispatch workflows.
- Require environment protection rules for production deployments.
gh pr create --fill — auto-fills title and body from commitsgh pr review <number> --approve or --request-changesgh workflow run deploy.yml --ref main — specify exact branchgh repo clone owner/repoKey takeaways
gh pr create --fill for auto-filled PRsgh workflow run with explicit parameters for production deploys20+ years shipping production infrastructure and CI/CD at scale. Notes here come from systems that actually shipped.
That's Git. Mark it forged?
3 min read · try the examples if you haven't