| name | github-cli |
| description | Use this skill when the user asks to work with GitHub from the command line using gh CLI. This includes managing repositories, issues, pull requests, releases, authentication, codespaces, actions, and any other GitHub operations. Use this skill for phrases like "create a PR", "manage issues", "clone a repo", "check gh status", or any GitHub CLI workflow. |
| version | 1.0.0 |
| license | MIT |
GitHub CLI (gh) Comprehensive Skill
Master the GitHub CLI (gh) to seamlessly work with GitHub from the command
line. This skill covers all major GitHub operations including repository
management, issues, pull requests, releases, authentication, and more.
When to Use This Skill
Trigger this skill when the user asks to:
- "Create a PR/issue/release"
- "Manage GitHub repository"
- "Clone/fork/update a repo"
- "Check/authenticate with gh"
- "Work with GitHub Actions"
- "Manage codespaces"
- "Search repos/issues/PRs"
- Any GitHub CLI operation
Prerequisites
Installation & Authentication
Check if gh is installed:
gh --version
Install gh (if not installed):
brew install gh
winget install --id GitHub.cli
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
Authenticate with GitHub:
gh auth login
Verify authentication:
gh auth status
Expected output:
github.com
✓ Logged in to github.com account <username> (keyring)
- Active account: true
- Git operations protocol: https
- Token: ghp_************************************
Core Command Categories
1. Repository Management
View Repository Info
gh repo view
gh repo view owner/repo
gh repo view --json name,description,visibility,owner
gh repo view --web
Clone Repository
gh repo clone
gh repo clone owner/repo
gh repo clone owner/repo my-directory
gh repo clone owner/repo -- --ssh
Create Repository
gh repo create
gh repo create my-repo \
--public \
--description "My awesome repository" \
--source=. \
--remote=origin \
--push
gh repo create my-private-repo --private
gh repo create my-repo --clone=false
Fork Repository
gh repo fork owner/repo
gh repo fork owner/repo --org my-org
gh repo fork owner/repo --clone
Update Repository Settings
gh repo edit --description "New description"
gh repo edit --visibility private
gh repo edit --add-topic "golang" --add-topic "proxy"
gh repo edit --default-branch main
2. Issue Management
List Issues
gh issue list
gh issue list \
--state open \
--author masx200 \
--label bug,enhancement \
--limit 20
gh issue list --state closed
gh issue list --json number,title,state,labels
gh issue list --repo owner/repo1 --repo owner/repo2
View Issue
gh issue view 123
gh issue view 123 --comments
gh issue view 123 --web
gh issue view 123 --json title,body,comments
Create Issue
gh issue create
gh issue create \
--title "Bug in authentication" \
--body "Detailed description of the bug"
gh issue create \
--title "Feature request" \
--body "Feature description" \
--label enhancement,good-first-issue
gh issue create \
--title "Fix critical bug" \
--body "Bug details" \
--assignee @me
gh issue create --template bug-report.md
Edit Issue
gh issue edit 123
gh issue comment 123 --body "This is a comment"
gh issue edit 123 --add-label "bug,priority"
gh issue edit 123 --remove-label "wontfix"
gh issue close 123
gh issue reopen 123
gh issue edit 123 --add-assignee username1,username2
gh issue edit 123 --remove-assignee username1
Search Issues
gh issue search "authentication" --open
gh search issues --repo owner/repo "label:bug"
gh search issues \
--state open \
--label "good first issue" \
--language go \
"stars:>100"
3. Pull Request Management
List Pull Requests
gh pr list
gh pr list \
--state open \
--author masx200 \
--base main \
--limit 20
gh pr list --state merged
gh pr list --state open --review required
gh pr list --json number,title,state,author,headRefName
View Pull Request
gh pr view 123
gh pr view 123 --diff
gh pr view 123 --comments
gh pr view 123 --json statusCheckRollup
gh pr view 123 --web
Create Pull Request
gh pr create
gh pr create \
--title "Add new feature" \
--body "Description of changes"
gh pr create \
--base main \
--head feature-branch \
--title "Feature implementation"
gh pr create \
--title "Refactor code" \
--body "Refactoring details" \
--reviewer username1,username2
gh pr create \
--title "Bug fix" \
--label bug,priority-high
gh pr create \
--title "WIP feature" \
--body "Work in progress" \
--draft
gh pr create \
--issue 123 \
--title "Fix issue #123"
gh pr create --template pr-template.md
Checkout Pull Request
gh pr checkout 123
gh pr checkout 123 --branchname pr-123
Edit Pull Request
gh pr edit 123
gh pr edit 123 --add-reviewer username1,username2
gh pr edit 123 --add-assignee username1
gh pr edit 123 --title "Updated title"
gh pr edit 123 --add-label "needs-review"
gh pr edit 123 --remove-label "wip"
gh pr edit 123 --mark-draft
gh pr edit 123 --ready-for-review
Manage Pull Request Reviews
gh pr edit 123 --add-reviewer username
gh pr view 123 --json reviews --jq '.reviews[]'
gh pr review 123 --approve --body "LGTM!"
gh pr review 123 --request-changes --body "Please fix these issues"
gh pr review 123 --comment --body "Just a comment"
gh pr review 123 --dismiss "No longer relevant"
Merge Pull Request
gh pr merge 123
gh pr merge 123 --merge
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 \
--merge \
--subject "Merge PR #123" \
--body "Detailed message"
gh pr merge 123 --delete-branch
gh pr merge 123 --yes
Close/Reopen Pull Request
gh pr close 123
gh pr close 123 --comment "Superseded by PR #456"
gh pr reopen 123
4. Authentication Management
Login/Logout
gh auth login
gh auth login --hostname enterprise.github.com
gh auth logout
gh auth logout --hostname enterprise.github.com
Status & Token
gh auth status
gh auth token
gh auth token --hostname enterprise.github.com
Switch Accounts
gh auth switch --username username
gh auth refresh
Git Integration
gh auth setup-git
5. Codespaces Management
List Codespaces
gh codespace list
gh codespace list --repo owner/repo
gh codespace list --json name,state,repository,createdAt
Create Codespace
gh codespace create
gh codespace create --branch main
gh codespace create --machine standardLinux32gb
gh codespace create --web
Connect to Codespace
gh codespace codespace
gh codespace ssh --codespace codespace-name
gh codespace code --codespace codespace-name
gh codespace view --web --codespace codespace-name
Delete Codespace
gh codespace delete --codespace codespace-name
gh codespace delete --all
6. GitHub Actions Management
List Workflow Runs
gh run list
gh run list --workflow "ci.yml"
gh run list --branch main
gh run list --limit 50
gh run list --json databaseId,status,conclusion,event,headBranch
View Run Details
gh run view 123456789
gh run view 123456789 --log
gh run view 123456789 --log-failed
gh run view 123456789 --web
gh run watch 123456789
Rerun Workflows
gh run rerun 123456789
gh run rerun 123456789 --failed
gh run cancel 123456789
gh workflow run ci.yml
Manage Workflow Files
gh workflow list
gh workflow view ci.yml
gh workflow view ci.yml --yaml
gh workflow enable ci.yml
gh workflow disable ci.yml
7. Release Management
List Releases
gh release list
gh release list --limit 20
gh release list --json name,tagName,publishedAt
View Release
gh release view v1.0.0
gh release view --latest
gh release view v1.0.0 --web
gh release download v1.0.0
gh release download v1.0.0 --pattern "*.tar.gz"
Create Release
gh release create v1.0.0
gh release create v1.0.0 \
--title "Version 1.0.0" \
--notes "Release notes here"
gh release create v1.0.0 \
--notes-file RELEASE_NOTES.md
gh release create v1.0.0 \
--notes "Draft notes" \
--draft
gh release create v1.0.0-beta.1 \
--notes "Beta release" \
--prerelease
gh release create v1.0.0 \
--target main \
--notes "Release notes"
gh release create v1.0.0 \
--notes "Release" \
./dist/binary-linux \
./dist/binary-darwin \
./dist/binary-windows.exe
Edit/Delete Release
gh release edit v1.0.0 --notes "Updated notes"
gh release delete v1.0.0 --yes
8. Search & Browse
Search Repositories
gh search repos "http proxy"
gh search repos \
--language go \
--stars ">100" \
"http proxy"
gh search repos --topic "proxy"
gh search repos "proxy" --json name,description,stargazersCount --limit 10
Search Issues & PRs
gh search issues "label:bug state:open"
gh search prs "state:open author:masx200"
gh search code "language:go Proxy()"
Browse in Browser
gh browse
gh browse --branch main --filename README.md
gh browse --issues
gh browse --pulls
gh browse --commit 9a8ebda
gh browse --settings
9. Organization Management
View Organization
gh org view my-org
gh org view my-org --json name,description,teams
gh org view my-org --web
List Organization Members
gh org list-members my-org
gh org list-members my-org --role admin
gh org list-members my-org --json login,role
Manage Organization Repositories
gh repo list my-org
gh repo create my-org/new-repo --public
10. Gist Management
List Gists
gh gist list
gh gist list --public
gh gist list --limit 50
View Gist
gh gist view gist-id
gh gist view gist-id --web
gh gist view gist-id --files
Create/Edit Gist
gh gist create file.txt
gh gist create file.txt --desc "My gist"
gh gist create file.txt --public
gh gist create file.txt --private
gh gist edit gist-id --file new-file.txt
gh gist delete gist-id
11. Label Management
List Labels
gh label list
gh label list --json name,color,description
Create Label
gh label create "bug" \
--color "d73a4a" \
--description "Something isn't working"
gh label create "enhancement" \
--color "#a2eeef" \
--description "New feature or request"
Edit/Delete Label
gh label edit "bug" --color "ff0000"
gh label delete "wontfix" --yes
12. Project Management
List Projects
gh project list
gh project list --org my-org
gh project list --json number,title,state
View Project
gh project view 1
gh project view 1 --json title,status,items
gh project view 1 --web
13. Status Command
Check Status
gh status
gh status --repo owner/repo1 --repo owner/repo2
gh status --limit 10
14. Alias & Extensions
Create Aliases
gh alias set prc 'pr create'
gh alias set list-prs 'pr list --state open --limit 20'
gh alias list
gh alias delete prc
Manage Extensions
gh extension install owner/extension-repo
gh extension list
gh extension remove extension-name
15. API Requests
Make API Requests
gh api /user
gh api "/repos/masx200/http-proxy-go-server/issues?state=open"
gh api \
--method POST \
-H "Accept: application/vnd.github.v3+json" \
/repos/owner/repo/issues \
-f title="New issue" \
-f body="Issue description"
gh api \
--method PATCH \
/repos/owner/repo/issues/123 \
-f state=closed
gh api /user/repos --paginate
gh api /user | jq '.name, .public_repos'
16. Configuration
View Configuration
gh config set
gh config get git_protocol
gh config set git_protocol ssh
gh config set editor vim
gh config set prompt enabled
Configuration Options
gh config set git_protocol ssh
gh config set editor code --wait
gh config set prompt enabled
gh config set pager less
17. SSH & GPG Keys
SSH Keys
gh ssh-key list
gh ssh-key add ~/.ssh/id_ed25519 --title "My laptop"
gh ssh-key delete 123456789
GPG Keys
gh gpg-key list
gh gpg-key add ~/.ssh/mykey.asc
gh gpg-key delete 123456789
18. Secrets Management
List Secrets
gh secret list
gh secret list --org my-org
gh secret list --env production
Set/Delete Secret
gh secret set MY_SECRET
gh secret set MY_SECRET < secret.txt
gh secret set MY_SECRET --env production
gh secret delete MY_SECRET
19. Variables Management (GitHub Actions)
List Variables
gh variable list
gh variable list --json name,value
Set/Delete Variable
gh variable set VAR_NAME "value"
gh variable set VAR_NAME "value" --env production
gh variable delete VAR_NAME
20. Completion Scripts
Generate Shell Completion
gh completion -s bash > /etc/bash_completion.d/gh
gh completion -s zsh > /usr/local/share/zsh/site-functions/_gh
gh completion -s fish > ~/.config/fish/completions/gh.fish
gh completion -s powershell | Out-File gh.ps1
Common Workflows & Examples
Workflow 1: Complete PR Creation Flow
git checkout main
git pull
git checkout -b feature/new-feature
git add .
git commit -m "feat: Add new feature"
git push -u origin feature/new-feature
gh pr create \
--title "Add new feature" \
--body "Detailed description" \
--reviewer username1,username2 \
--label enhancement
gh pr status
Workflow 2: Issue Triage
gh issue list --state open --limit 50
gh issue view 123
gh issue edit 123 \
--add-label "bug,priority-high" \
--add-assignee @me
gh issue comment 123 --body "Working on this"
git checkout -b fix/issue-123
gh pr create \
--issue 123 \
--title "Fix issue #123" \
--body "Fixes #123"
Workflow 3: Repository Setup
gh repo create my-new-repo --public --clone
cd my-new-repo
echo "# My New Repo" > README.md
git add README.md
git commit -m "Initial commit"
git push
gh repo edit --add-topic "golang,cli,tool"
gh label create "bug" --color "d73a4a"
gh label create "enhancement" --color "a2eeef"
gh api \
--method PUT \
-H "Accept: application/vnd.github.v3+json" \
/repos/$(gh repo view --json owner,name --jq '.owner.login + "/" + .name')/branches/main/protection \
-f required_status_checks='{"strict":true,"contexts":[]}' \
-f enforce_admins=true \
-f required_pull_request_reviews='{"dismiss_stale_reviews":true}'
Workflow 4: Release Management
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0
gh release create v1.0.0 \
--title "Version 1.0.0" \
--notes-file RELEASE_NOTES.md
gh release upload v1.0.0 \
./dist/binary-linux-amd64 \
./dist/binary-darwin-amd64 \
./dist/binary-windows-amd64.exe
gh release view v1.0.0 --web
Workflow 5: Fork & Contribute
gh repo fork owner/repo --clone
cd repo
git checkout -b feature/contribution
git add .
git commit -m "feat: Add contribution"
git push -u origin feature/contribution
gh pr create \
--repo owner/repo \
--base main \
--title "Add contribution" \
--body "Description of changes"
Workflow 6: Bulk Operations
gh issue list --label "wontfix" --json number --jq '.[].number' | \
xargs -I {} gh issue close {} --comment "Closed as wontfix"
gh issue list --state open --json number --jq '.[].number' | \
xargs -I {} gh issue edit {} --add-label "triage"
gh pr list --state open --label "ready-to-merge" --json number --jq '.[].number' | \
xargs -I {} gh pr merge {} --merge --yes
Tips & Best Practices
DO ✅
-
Use aliases for frequently used commands
gh alias set prs 'pr list --state open'
gh alias set issues 'issue list --state open'
-
Enable shell completion for better productivity
-
Use JSON output with jq for scripting:
gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
-
Create templates for common PR/issue descriptions
-
Use web flag to open in browser for complex operations:
gh pr view --web
-
Check auth status before running sensitive operations
-
Use --help flag to explore subcommands:
gh pr create --help
-
Leverage search for complex queries
-
Use pagination for large result sets:
gh issue list --limit 100
-
Automate with scripts using gh in CI/CD pipelines
DON'T ❌
-
NEVER hardcode tokens - let gh handle authentication
-
DON'T ignore errors - check exit codes and handle failures
-
NEVER commit secrets - use gh secret for sensitive data
-
DON'T use --yes in scripts without proper validation
-
NEVER delete resources without confirmation (unless intentional)
-
DON'T forget to push tags before creating releases
-
NEVER use --web in automated scripts
-
DON'T ignore rate limits when making API calls
-
NEVER assume gh is installed - check and handle missing
-
DON'T use personal access tokens when gh auth is available
Troubleshooting
Issue: "gh not found"
Solution:
which gh
Issue: "gh: not logged in"
Solution:
gh auth login
gh auth status
Issue: "Permission denied"
Solution:
gh repo view
gh auth refresh
Issue: "Repository not found"
Solution:
git remote -v
git remote set-url origin https://github.com/owner/repo.git
Issue: "gh is slow"
Solution:
gh config get git_protocol
gh config set git_protocol ssh
Issue: "API rate limit exceeded"
Solution:
gh api /rate_limit
gh auth login
Advanced Usage
JSON Processing with jq
gh pr list --json title --jq '.[].title'
gh pr list --json number,title,labels --jq '.[] | select(.labels[].name == "bug")'
gh issue list --assignee @me --json number,title --jq '.[] | "#\(.number): \(.title)"'
gh pr list --json author --jq 'group_by(.author.login) | map({author: .[0].author.login, count: length})'
Shell Scripting
#!/bin/bash
if ! gh auth status &> /dev/null; then
echo "Not authenticated with gh"
exit 1
fi
if git rev-parse "$1" &> /dev/null; then
echo "Tag $1 already exists"
exit 1
fi
git tag -a "$1" -m "Release $1"
git push origin "$1"
gh release create "$1" --notes-file RELEASE_NOTES.md
Git Integration
BRANCH=$(git branch --show-current)
if [[ $BRANCH == feature/* ]]; then
echo "Creating PR for $BRANCH"
gh pr create --base main --head "$BRANCH" --draft
fi
Additional Resources
Keyboard Shortcuts & Tips
gh pr list | fzf | gh pr view $(awk '{print $1}')
gh pr view --web $(gh pr list --json number --jq '.[0].number')
gh issue create --title "$1" --body "$(cat issue-template.md)"
Remember: The GitHub CLI is a powerful tool - use it wisely to automate your
GitHub workflows and boost your productivity! 🚀