| name | github-cli |
| description | Execute GitHub CLI (gh) commands to manage repositories, pull requests, issues, workflows, and more. Use when working with GitHub operations like creating PRs, listing issues, managing branches, checking workflow runs, or any gh command automation. |
GitHub CLI Automation
Use the GitHub CLI (gh) to automate GitHub repository operations efficiently.
Prerequisites
- GitHub CLI must be installed:
gh --version
- Authentication required:
gh auth status
Core Operations
Repository Management
gh repo view
gh repo clone owner/repo
gh repo fork
gh repo create my-new-repo --public
Pull Requests
gh pr create --title "Feature: Add new functionality" --body "Description"
gh pr list --state open
gh pr list --author @me
gh pr view 123
gh pr checkout 123
gh pr merge 123 --squash
gh pr status
Issues
gh issue create --title "Bug: Something broke" --body "Description"
gh issue list --state open
gh issue list --label bug --assignee @me
gh issue view 456
gh issue close 456
gh issue reopen 456
Workflow Runs
gh run list --limit 10
gh run view 12345
gh run watch
gh run rerun 12345
gh run view 12345 --log
Branches
gh api repos/:owner/:repo/branches
gh api -X DELETE repos/:owner/:repo/git/refs/heads/branch-name
Releases
gh release create v1.0.0 --title "Release 1.0.0" --notes "Release notes"
gh release list
gh release download v1.0.0
Gists
gh gist create file.txt --public
gh gist list
gh gist view <gist-id>
Advanced Usage
JSON Output for Parsing
Many commands support --json for structured output:
gh pr list --json number,title,state,headRefName
gh issue list --json number,title,labels,state
gh pr list --json number,title | jq '.[] | select(.title | contains("bug"))'
API Access
Direct API access for advanced operations:
gh api repos/:owner/:repo/branches
gh api repos/:owner/:repo/pulls --paginate
gh api repos/:owner/:repo/issues -f title="New Issue" -f body="Description"
Checking for Stale Branches
git branch -r --merged main | grep -v 'main\|HEAD'
gh pr list --state merged --json headRefName,mergedAt
Best Practices
- Always check auth status first: Run
gh auth status before operations
- Use structured output: Prefer
--json when parsing results programmatically
- Check command success: Verify exit codes and output before proceeding
- Use help: Run
gh <command> --help for detailed syntax
- Batch operations: Combine commands with shell scripting for bulk operations
Common Workflows
Creating and Merging a PR
git push origin feature-branch
gh pr create --title "Feature: Description" --body "Detailed description"
gh pr checks
gh pr merge --squash
Cleaning Up Merged Branches
gh pr list --state merged --json headRefName --limit 20
Release Management
git tag v1.0.0
git push --tags
gh release create v1.0.0 --generate-notes
gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes here"
Error Handling
if ! command -v gh &> /dev/null; then
echo "GitHub CLI not installed"
exit 1
fi
if ! gh auth status &> /dev/null; then
echo "Not authenticated. Run: gh auth login"
exit 1
fi
Reference