Setup
Installation
brew install ghmacOS via Homebrew
sudo apt install ghDebian / Ubuntu
winget install GitHub.cliWindows via winget
conda install ghVia conda-forge
Authentication
gh auth login # interactive login gh auth login --with-token < token.txt gh auth status # check auth state gh auth refresh -s repo,gist # add scopes
Configuration
gh config set editor vim gh config set pager less gh config set git_protocol ssh gh config list
Repos
Repository Commands
gh repo create my-app --public --clone gh repo clone owner/repo gh repo fork owner/repo --clone gh repo view owner/repo --web
Repo Options
--public | --privateSet repository visibility
--template owner/repoCreate from template repo
--cloneClone after creating
--add-readmeInitialize with README
gh repo list ownerList repos for owner
gh repo delete owner/repoDelete repository (with confirm)
gh repo rename new-nameRename current repo
gh repo archive owner/repoArchive a repository
Issues
Managing Issues
gh issue create --title "Bug" --body "Details here" gh issue list --state open --label bug gh issue view 42 gh issue close 42 --reason completed
Issue Options
--assignee @meAssign to yourself
--label bug,urgentAdd labels
--milestone v2.0Set milestone
--project "Board"Add to project
gh issue edit 42Edit issue interactively
gh issue reopen 42Reopen a closed issue
gh issue comment 42 -b "msg"Add comment to issue
gh issue pin 42Pin issue to repo
Pull Requests
Creating & Managing PRs
gh pr create --title "feat: add auth" --body "..." gh pr create --fill # title/body from commits gh pr list --state open gh pr view 123 --web
Review & Merge
gh pr checkout 123 # check out PR branch gh pr diff 123 # view PR diff gh pr review 123 --approve gh pr merge 123 --squash --delete-branch
PR Options
--draftCreate as draft PR
--reviewer user1,user2Request reviewers
--base mainSet base branch
--merge | --squash | --rebaseMerge strategy
--autoEnable auto-merge when checks pass
--delete-branchDelete branch after merge
gh pr ready 123Mark draft PR as ready
Actions
Workflow Commands
gh run list # recent runs gh run view 12345 # run details gh run view 12345 --log-failed # failed step logs gh run watch 12345 # live status
Triggering & Managing
gh workflow run deploy.yml --ref main gh workflow list gh workflow view deploy.yml gh run rerun 12345 --failed # rerun failed jobs
Actions Options
-f key=valuePass input to workflow_dispatch
--jsonOutput as JSON
-b branchFilter by branch
gh run download 12345Download run artifacts
gh cache listList Actions caches
gh cache delete KEYDelete a cache entry
Releases
Managing Releases
gh release create v1.0.0 --generate-notes gh release create v1.0.0 ./dist/*.tar.gz gh release list gh release view v1.0.0
Release Options
--title "Release v1.0"Set release title
--notes "Changelog here"Set release notes inline
--notes-file CHANGELOG.mdNotes from file
--generate-notesAuto-generate from commits
--draftCreate as draft
--prereleaseMark as prerelease
--latestMark as latest release
gh release download v1.0.0Download release assets
gh release delete v1.0.0Delete a release
gh release edit v1.0.0Edit release metadata
Gists
Gist Commands
gh gist create file.py -d "My snippet" gh gist create file1.js file2.js # multi-file gist gh gist list gh gist view
Gist Options
-d "description"Set gist description
--publicCreate public gist (default: secret)
--webOpen gist in browser
gh gist edit <id>Edit gist files
gh gist clone <id>Clone gist locally
gh gist delete <id>Delete a gist
API
Making API Calls
gh api repos/owner/repo gh api repos/owner/repo/issues --method POST \ -f title="Bug" -f body="Details" gh api graphql -f query='{ viewer { login } }'
Formatting Output
gh api repos/owner/repo --jq '.stargazers_count' gh api repos/owner/repo --template '{{.full_name}}' gh pr list --json number,title --jq '.[].title'
API Options
--method GET|POST|PUT|DELETEHTTP method
-f key=valueSet string field
-F key=@fileSet field from file
--jq 'expression'Filter JSON with jq syntax
--template 'tmpl'Format with Go template
--paginateFetch all pages
-H 'Accept: ...'Set custom header
Aliases
Managing Aliases
gh alias set co 'pr checkout' gh alias set bugs 'issue list --label bug' gh alias set last 'run list -L 1' gh alias list
Advanced Aliases
# Alias with shell command gh alias set --shell pv 'gh pr view --json url --jq .url | pbcopy' # Delete alias gh alias delete co
Alias Tips
gh alias set name 'cmd'Create simple alias
--shellAlias runs via shell (supports pipes)
gh alias listShow all defined aliases
gh alias delete nameRemove an alias
Common Patterns
Daily Workflow
gh issue list --assignee @me # my open issues gh pr status # PRs needing attention gh pr checks 123 # CI status for PR gh run list -b main -L 5 # recent CI runs
Searching
gh search repos --language rust --stars ">1000" gh search issues --repo owner/repo "memory leak" gh search prs --state open --review required
Useful Flags
--json field1,field2Output specific fields as JSON
--jq 'expr'Filter JSON output
-L NLimit results to N items
--webOpen result in browser
-R owner/repoTarget a specific repository
GH_TOKEN=xxxAuth via environment variable