Most developers spend hours every week switching back and forth between their code editor, terminal, and browser just to perform routine GitHub actions: creating pull requests, reading code review comments, checking why a CI pipeline failed, or drafting releases. The official GitHub CLI (gh) bridges this gap, allowing you to manage GitHub's full feature set directly from your command line.
5 Essential Everyday `gh` Workflows
1. Checking Out Pull Requests Locally in One Command
Instead of manually finding the remote fork URL, fetching the branch, and switching to it, simply run:
gh pr checkout 42
This automatically configures the upstream tracking branch, switches your working tree, and lets you immediately compile and test a colleague's PR.
2. Interactive Pull Request Creation
gh pr create --web # Opens browser with prefilled branch and diff
gh pr create --fill # Automatically uses commit messages for PR title & description
3. Real-Time CI Pipeline Monitoring
Instead of refreshing the GitHub Actions web tab to see if tests pass before merging, run:
gh run watch # Live updates in your terminal as steps complete
gh run view --log-failed # Immediately streams only failing test logs
4. Creating Binary Releases with Assets
gh release create v1.4.0 ./dist/* --generate-notes --title "Release v1.4.0"
Terminal PR Review Loop via `gh`
Supercharging `gh` with Extensions
The GitHub CLI includes a modular extension architecture. Developers can install community plugins using gh extension install <repo>. Two of the most useful extensions are:
dlvhdr/gh-dash: A rich, customizable terminal dashboard (built with Bubbletea) displaying your pull requests, issues, and notifications in side-by-side terminal panes.github/gh-copilot: Query GitHub Copilot from the command line to generate explanations or suggest bash commands for obscure utilities.
Essential `gh` Commands Quick Reference
| Task | Command | Primary Benefit |
|---|---|---|
| Clone Repo | gh repo clone owner/repo | Sets up authenticated HTTPS/SSH git remote automatically |
| Inspect CI Logs | gh run view --log-failed | Immediately isolates test failures without web navigation |
| Merge Pull Request | gh pr merge --squash --delete-branch | Squashes, merges, and purges remote/local branches cleanly |
| Raw API Query | gh api repos/:owner/:repo/pulls | Handles authentication headers and JSON formatting |
When running gh auth login via web browser, the generated OAuth token grants standard repository permissions. However, if you plan to trigger manual workflows (gh workflow run) or inspect organization secrets, you must request elevated scopes using: gh auth refresh -s workflow,admin:org. Without these scopes, CI triggering commands will return generic HTTP 403: Resource not accessible by personal access token errors.
To install gh on your machine or browse full manual pages, visit the official site at cli.github.com or the open-source GitHub CLI repository.
Discussion & Issues
Comments
Post a Comment