iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

gh CLI

gh is the official GitHub CLI - it folds half the workflow out of the browser and into your shell.

GitHub CLI workflows

EXAMPLE
# Install
# macOS:   brew install gh
# Ubuntu:  apt install gh
# Windows: scoop install gh

# Authenticate once
gh auth login

# 1. PR workflow
git checkout -b feat/login-form
# ... edit, commit, push ...
gh pr create --fill --base main             # --fill uses commits as title/body
gh pr view --web                            # open in browser
gh pr checks                                # CI status
gh pr ready                                 # mark draft as ready

# 2. Review a PR locally
gh pr checkout 1234                         # check out their branch
# ... run tests, leave comments via gh pr review --comment -b 'looks good'

# 3. Approve and merge
gh pr review --approve -b 'LGTM'
gh pr merge --squash --delete-branch        # squash + delete remote branch

# 4. Issues
gh issue create --title 'Search returns empty on emoji' --body 'Reproduce: ...'
gh issue list --assignee @me --state open
gh issue view 42 --comments

# 5. Releases
gh release create v1.4.0 \
  --title 'v1.4.0 - Search fixes' \
  --notes 'See CHANGELOG.md' \
  ./dist/myapp.tar.gz                       # attach binaries

# 6. Runs (Actions)
gh run list -L 10
gh run watch                                # live status
gh run rerun <run-id>
gh run download <run-id>                    # artifacts

# 7. Workflow status from CLI
gh workflow run deploy.yml -f environment=staging

# 8. Useful aliases
gh alias set co 'pr checkout'
gh alias set up 'pr create --fill'
gh alias set ck 'pr checks'

# 9. gh api for everything else
gh api repos/:owner/:repo/branches/main/protection
gh api graphql -f query='query { viewer { login } }'

# 10. gh extensions
gh extension install dlvhdr/gh-dash      # interactive dashboard
gh extension install yusukebe/gh-markdown-preview

Why it matters

gh closes the loop between editor and GitHub. Once you script common workflows (checkout / push / open PR / watch CI) you stop tab-switching mid-task. For anything not covered by a verb, gh api hits the REST and GraphQL endpoints directly.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
gh pr list
gh pr view 42 --comments
gh issue create
Try it Yourself »

Discussion

Loading…