Overview
This series teaches GitHub CLI through heavily annotated, self-contained shell examples. Each example focuses on a single command or pattern and includes inline annotations showing the expected output, explaining what each flag does, and describing why the approach matters in real workflows.
Series Structure
The examples are organized into three levels based on complexity:
- Beginner — Authentication, repository operations, issue management, pull request basics, and configuration
- Intermediate — Advanced PR workflows, releases, gists, GitHub Actions management, secrets, variables, labels, SSH keys, and Codespaces
- Advanced — REST and GraphQL API calls, pagination, jq filtering, extensions, scripting patterns, search, cache management, attestations, GPG keys, Projects, and CI/CD integration
Structure of Each Example
Every example follows a consistent five-part format:
- Brief Explanation — what the command does and why it exists (2-3 sentences)
- Mermaid Diagram — visual representation of the operation or data flow (when appropriate)
- Heavily Annotated Code — shell commands with
# =>comments showing output and effects - Key Takeaway — the core insight to retain from the example (1-2 sentences)
- Why It Matters — production relevance and real-world impact (50-100 words)
How to Use This Series
Each example contains a complete, runnable shell snippet. Read the # => annotations alongside
the commands to understand both the mechanics and the intent. The examples within each level
build thematically, so reading sequentially provides the fullest understanding. Experienced
developers can also jump directly to the level and topic relevant to their current task.
Examples by Level
Beginner (Examples 1–28)
- Example 1: Interactive Login
- Example 2: Non-Interactive Login with Token
- Example 3: Check Authentication Status
- Example 4: Log Out
- Example 5: Clone a Repository
- Example 6: Create a New Repository
- Example 7: View a Repository
- Example 8: List Your Repositories
- Example 9: Fork a Repository
- Example 10: Create an Issue
- Example 11: List Issues
- Example 12: View an Issue
- Example 13: Close and Reopen an Issue
- Example 14: Edit an Issue
- Example 15: Create a Pull Request
- Example 16: List Pull Requests
- Example 17: View a Pull Request
- Example 18: Check Out a Pull Request Branch
- Example 19: Merge a Pull Request
- Example 20: Set a Configuration Value
- Example 21: Get and List Configuration Values
- Example 22: Create an Alias
- Example 23: Add a Comment to an Issue
- Example 24: List Repository Collaborators and Topics
- Example 25: Pin and Unpin Issues
- Example 26: Transfer an Issue
- Example 27: Lock and Unlock an Issue
- Example 28: Delete a Repository
Intermediate (Examples 29–56)
- Example 29: Review a Pull Request
- Example 30: Mark a PR as Ready for Review
- Example 31: Check PR CI Status
- Example 32: View PR Diff
- Example 33: Add a Comment to a Pull Request
- Example 34: Create a Release
- Example 35: List and View Releases
- Example 36: Delete a Release
- Example 37: Download Release Assets
- Example 38: Create a Gist
- Example 39: List and View Gists
- Example 40: Edit and Delete a Gist
- Example 41: List Workflow Runs
- Example 42: View a Workflow Run
- Example 43: Watch a Running Workflow
- Example 44: Re-run a Failed Workflow
- Example 45: List and Enable/Disable Workflows
- Example 46: Trigger a Workflow Manually
- Example 47: Manage Repository Secrets
- Example 48: Manage Environment Secrets
- Example 49: Manage Variables
- Example 50: Create and List Labels
- Example 51: Edit and Delete Labels
- Example 52: Add and List SSH Keys
- Example 53: Codespace: Create and List
- Example 54: SSH into a Codespace
- Example 55: Stop and Delete a Codespace
- Example 56: Port Forwarding in a Codespace
Advanced (Examples 57–85)
- Example 57: Call the GitHub REST API
- Example 58: Make POST and PATCH API Requests
- Example 59: Extract Fields with --jq
- Example 60: Paginate API Results
- Example 61: Run a GraphQL Query
- Example 62: GraphQL with Variables and Pagination
- Example 63: Install and Use an Extension
- Example 64: Create a Shell Extension
- Example 65: Search Repositories
- Example 66: Search Issues and Pull Requests
- Example 67: Search Code and Commits
- Example 68: Output JSON for Scripting
- Example 69: Combine gh Commands in a Shell Script
- Example 70: Loop Over Repositories
- Example 71: Use gh in GitHub Actions Workflows
- Example 72: List and Delete Workflow Caches
- Example 73: Verify Artifact Attestations
- Example 74: Manage GPG Keys
- Example 75: List and View Projects
- Example 76: Create a Project and Add Items
- Example 77: List Project Fields
- Example 78: Shell Alias for Complete PR Workflow
- Example 79: Automated Release Script
- Example 80: Stale Issue Management Script
- Example 81: Cross-Repository Deployment Coordination
- Example 82: Mermaid Diagram: gh API Data Flow
- Example 83: Mermaid Diagram: PR Lifecycle with gh
- Example 84: gh in Pre-push Hooks
- Example 85: Complete Onboarding Automation Script
Last updated March 31, 2026