GitHub CLI (gh)
GitHub functionality in the terminal.
Repository Management
bash
1gh repo view # View current repo
2gh repo view owner/repo # View specific repo
3gh repo view --web # Open in browser
4gh repo clone owner/repo # Clone repository
5gh repo fork # Fork current repo
6gh repo create name # Create new repo
7gh repo create name --private # Create private repo
8gh repo list # List your repos
9gh repo list owner # List user/org repos
10gh repo sync # Sync fork with upstream
Issues
bash
1# Listing
2gh issue list # List open issues
3gh issue list --state all # All issues
4gh issue list --assignee @me # Assigned to you
5gh issue list --label bug # Filter by label
6gh issue list --json number,title,state
7
8# Viewing
9gh issue view 123 # View issue
10gh issue view 123 --comments # With comments
11gh issue view 123 --web # Open in browser
12
13# Creating
14gh issue create # Interactive create
15gh issue create --title "T" --body "B"
16gh issue create --title "T" --label bug,high-priority
17
18# Managing
19gh issue close 123 # Close issue
20gh issue reopen 123 # Reopen issue
21gh issue comment 123 --body "msg" # Add comment
22gh issue edit 123 --add-label bug # Edit issue
Pull Requests
bash
1# Listing
2gh pr list # List open PRs
3gh pr list --state merged # Merged PRs
4gh pr list --author @me # Your PRs
5gh pr list --json number,title,author
6
7# Viewing
8gh pr view 123 # View PR
9gh pr view 123 --web # Open in browser
10gh pr checks 123 # View CI status
11gh pr diff 123 # View PR diff
12
13# Creating
14gh pr create # Interactive create
15gh pr create --fill # Auto-fill from commits
16gh pr create --draft # Create as draft
17gh pr create --title "feat: X" --body "Description"
18
19# Reviewing
20gh pr review 123 --approve # Approve PR
21gh pr review 123 --request-changes --body "Fix X"
22gh pr review 123 --comment -b "m" # Comment on PR
23
24# Merging
25gh pr merge 123 # Merge PR
26gh pr merge 123 --squash # Squash merge
27gh pr merge 123 --rebase # Rebase merge
28gh pr merge 123 --delete-branch # Delete branch after
29
30# Other
31gh pr checkout 123 # Checkout PR locally
32gh pr ready 123 # Mark as ready
Search
bash
1# Repositories
2gh search repos "react language:typescript stars:>1000"
3gh search repos "owner:facebook" --limit 20
4
5# Issues
6gh search issues "repo:owner/repo is:open label:bug"
7gh search issues "author:@me is:open"
8
9# PRs
10gh search prs "repo:owner/repo is:open review:required"
11
12# Code
13gh search code "function main repo:owner/repo"
14gh search code "filename:config.json owner:org"
15
16# Commits
17gh search commits "fix bug repo:owner/repo"
Releases
bash
1gh release list # List releases
2gh release view v1.0.0 # View release
3gh release create v1.0.0 # Create release
4gh release create v1.0.0 --draft # Draft release
5gh release create v1.0.0 ./dist/* # With assets
6gh release download v1.0.0 # Download assets
7gh release delete v1.0.0 # Delete release
Gists
bash
1gh gist list # List your gists
2gh gist create file.txt # Create from file
3gh gist create -p file.txt # Public gist
4gh gist view <id> # View gist
5gh gist edit <id> # Edit gist
6gh gist clone <id> # Clone gist
7gh gist delete <id> # Delete gist
API Requests
bash
1# REST API
2gh api repos/{owner}/{repo}
3gh api repos/{owner}/{repo}/issues
4gh api /user
5
6# POST request
7gh api -X POST repos/{owner}/{repo}/issues \
8 -f title="Bug" -f body="Description"
9
10# With query parameters
11gh api -X GET search/issues -f q='repo:cli/cli is:open'
12
13# With pagination
14gh api repos/{owner}/{repo}/issues --paginate
15
16# Filter with jq
17gh api repos/{owner}/{repo}/issues --jq '.[].title'
18
19# GraphQL
20gh api graphql -f query='{ viewer { login } }'
21gh api graphql -F owner='{owner}' -F name='{repo}' -f query='
22 query($name: String!, $owner: String!) {
23 repository(owner: $owner, name: $name) {
24 stargazerCount
25 }
26 }
27'
Workflows (GitHub Actions)
bash
1gh workflow list # List workflows
2gh workflow run <workflow> # Trigger workflow
3gh run list # List workflow runs
4gh run view <run-id> # View run details
5gh run download <run-id> # Download artifacts
6
7# Watch run (use tmux)
8tmux new -d -s gh-watch 'gh run watch <run-id>'
JSON Output
bash
1gh issue list --json number,title,state
2gh pr list --json number,title,author
3
4# Filter with jq
5gh issue list --json title --jq '.[].title'
6gh pr list --json number,title --jq '.[] | "\(.number): \(.title)"'
7gh issue list --json number,title,state --jq '.[] | select(.state == "open")'
Common Flags
| Flag | Description |
|---|
-R owner/repo | Target specific repository |
--web | Open in browser |
--json fields | Output as JSON |
--jq query | Filter JSON output |
--limit N | Limit results |
--state open/closed/all | Filter by state |
Tips
- Use
{owner} and {repo} placeholders in API calls (auto-filled)
- Use
--web to open any resource in browser
- Use
--json with --jq for scriptable output
gh auth status to check authentication
gh config set editor vim to set default editor
- Use
gh alias set to create shortcuts