GitHub CLI gives you full control over GitHub Actions workflows, runs, and caches from the terminal.
Workflows (gh workflow)
Listing Workflows
gh workflow list
# Include disabled workflows
gh workflow list --all
# JSON output
gh workflow list --json name,state,idViewing a Workflow
gh workflow view build.yml
gh workflow view build.yml --web
# View by ID
gh workflow view 12345Enabling / Disabling Workflows
gh workflow disable build.yml
gh workflow enable build.ymlTriggering a Workflow Manually
For workflows with workflow_dispatch triggers:
# Trigger on the default branch
gh workflow run build.yml
# Trigger on a specific branch
gh workflow run build.yml --ref feature-branch
# Pass input parameters (defined in the workflow YAML)
gh workflow run deploy.yml -f environment=staging -f version=1.2.0
# Pass inputs from a JSON file
gh workflow run deploy.yml --json < inputs.jsonRuns (gh run)
Listing Runs
# Recent runs (all workflows)
gh run list
# Filter by workflow
gh run list --workflow build.yml
# Filter by branch
gh run list --branch main
# Filter by status
gh run list --status failure
gh run list --status success
gh run list --status in_progress
# Filter by user
gh run list --user octocat
# Limit
gh run list --limit 50
# JSON output
gh run list --json databaseId,status,conclusion,headBranchViewing a Run
# Interactive — choose a job to see its logs
gh run view 123456789
# View specific job logs
gh run view 123456789 --job 987654321
# Show only the log output
gh run view 123456789 --log
# Show only failed step logs
gh run view 123456789 --log-failed
# Open in browser
gh run view 123456789 --webWatching a Run in Real Time
# Watch until completion
gh run watch 123456789
# Watch with live log output
gh run watch 123456789 --exit-status
# Watch the most recent run
gh run watch--exit-status makes the command exit with a non-zero code if the run fails — useful in scripts.
Rerunning a Failed Run
# Rerun all jobs
gh run rerun 123456789
# Rerun only failed jobs
gh run rerun 123456789 --failed
# Rerun a specific job
gh run rerun 123456789 --job 987654321
# Enable debug logging
gh run rerun 123456789 --debugCancelling a Run
gh run cancel 123456789Deleting a Run
gh run delete 123456789Downloading Run Artifacts
# Download all artifacts
gh run download 123456789
# Download to a specific directory
gh run download 123456789 --dir ./artifacts
# Download a specific artifact by name
gh run download 123456789 --name build-output
# Download by pattern
gh run download 123456789 --pattern "*-linux-*"Caches (gh cache)
GitHub Actions caches (e.g., actions/cache) can be managed from the CLI.
Listing Caches
gh cache list
# Sort by size or last accessed
gh cache list --sort size
gh cache list --sort last_accessed
# Limit
gh cache list --limit 50
# JSON output
gh cache list --json key,sizeInBytes,lastAccessedAtDeleting Caches
# Delete by key
gh cache delete <cache-key>
# Delete all caches
gh cache delete --allA CI/CD Monitoring Workflow
# 1. Push your code
git push origin main
# 2. Watch the triggered run
gh run watch
# 3. If it fails, check the logs
gh run view --log-failed
# 4. Fix, push again, rerun
gh run rerun --failed
# 5. Download artifacts
gh run download --name build-outputExercises
- List your workflows:
gh workflow list - List recent runs:
gh run list --limit 5 - View a specific run:
gh run view <run-id> - Watch a run in real time:
gh run watch - List Actions caches:
gh cache list