GitHub CLI Power Tricks
gh CLI tricks beyond the basics.
PR commands
The gh CLI's PR commands are faster than the web UI for routine actions. Create, review, check status, merge: all from the terminal without context-switching to a browser tab.
gh pr create. Pulls title and body from the latest commit; opens the PR in seconds. Drops the "create PR in browser" detour.gh pr review --approve / --request-changes. Approve, request changes, or comment from the terminal. No tab-switching mid-review.gh pr checks. CI status from the terminal. Refreshes faster than the web UI and scripts cleanly.gh pr merge --squash. Squash-merge from the terminal. Supports clean main-branch history without a browser visit.
Scripting
The gh CLI exposes the full GitHub API as a scriptable surface. Build custom workflows the web UI cannot do: bulk PR queries, repository audits, label management, GraphQL traversal, all using your already-authenticated session.
gh api endpoint. Arbitrary REST endpoint call. Returns JSON; pipe intojq.- Custom scripts. Bespoke automation per team: bulk PR queries, label management, repository auditing, security review tooling.
gh api graphql. GraphQL endpoint for complex multi-resource queries. One round-trip instead of N REST calls.- Auth-cached token. Scripts use the
gh auth loginsession. Avoids embedding personal access tokens in code or env files.
Aliases
Aliases turn the gh CLI into a personal shortcut layer. Frequent commands compress to a few keystrokes; team-shared alias sets bring onboarding consistency; dotfiles-tracked aliases survive machine moves.
gh alias set my-prs 'pr list --author @me'. Named shortcut for a frequent command shape.gh my-prsreplaces the longer form.- Speeds frequent commands. Seconds saved per invocation, compounding across daily use. Real time savings.
- Team-shared alias set. Recommended aliases per team. Onboarding consistency without re-explaining each engineer's setup.
- Version-controlled aliases. Dotfiles-tracked alias config. Survives machine moves; same shortcuts on every laptop.