Setup
Instalasi
brew install ghmacOS via Homebrew
sudo apt install ghDebian / Ubuntu
winget install GitHub.cliWindows via winget
conda install ghVia conda-forge
Autentikasi
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
Konfigurasi
gh config set editor vim gh config set pager less gh config set git_protocol ssh gh config list
Repo
Perintah Repository
gh repo create my-app --public --clone gh repo clone owner/repo gh repo fork owner/repo --clone gh repo view owner/repo --web
Opsi Repo
--public | --privateAtur visibilitas repository
--template owner/repoBuat dari template repo
--cloneClone setelah membuat
--add-readmeInisialisasi dengan README
gh repo list ownerTampilkan repo untuk owner
gh repo delete owner/repoHapus repository (dengan konfirmasi)
gh repo rename new-nameGanti nama repo saat ini
gh repo archive owner/repoArsipkan repository
Issue
Mengelola Issue
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
Opsi Issue
--assignee @meTetapkan ke diri sendiri
--label bug,urgentTambah label
--milestone v2.0Atur milestone
--project "Board"Tambah ke project
gh issue edit 42Edit issue secara interaktif
gh issue reopen 42Buka kembali issue yang ditutup
gh issue comment 42 -b "msg"Tambah komentar ke issue
gh issue pin 42Pin issue ke repo
Pull Request
Membuat & Mengelola PR
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
Opsi PR
--draftBuat sebagai draft PR
--reviewer user1,user2Minta reviewer
--base mainAtur base branch
--merge | --squash | --rebaseStrategi merge
--autoAktifkan auto-merge saat checks lulus
--delete-branchHapus branch setelah merge
gh pr ready 123Tandai draft PR sebagai siap
Actions
Perintah Workflow
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
Memicu & Mengelola
gh workflow run deploy.yml --ref main gh workflow list gh workflow view deploy.yml gh run rerun 12345 --failed # rerun failed jobs
Opsi Actions
-f key=valueTeruskan input ke workflow_dispatch
--jsonOutput sebagai JSON
-b branchFilter berdasarkan branch
gh run download 12345Unduh artifact run
gh cache listTampilkan cache Actions
gh cache delete KEYHapus entri cache
Rilis
Mengelola Rilis
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
Opsi Rilis
--title "Release v1.0"Atur judul rilis
--notes "Changelog here"Atur catatan rilis secara inline
--notes-file CHANGELOG.mdCatatan dari file
--generate-notesBuat catatan otomatis dari commit
--draftBuat sebagai draft
--prereleaseTandai sebagai prerelease
--latestTandai sebagai rilis terbaru
gh release download v1.0.0Unduh aset rilis
gh release delete v1.0.0Hapus rilis
gh release edit v1.0.0Edit metadata rilis
Gist
Perintah Gist
gh gist create file.py -d "My snippet" gh gist create file1.js file2.js # multi-file gist gh gist list gh gist view
Opsi Gist
-d "description"Atur deskripsi gist
--publicBuat gist publik (default: secret)
--webBuka gist di browser
gh gist edit <id>Edit file gist
gh gist clone <id>Clone gist secara lokal
gh gist delete <id>Hapus gist
API
Memanggil API
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 } }'
Format 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'
Opsi API
--method GET|POST|PUT|DELETEHTTP method
-f key=valueSet field string
-F key=@fileSet field dari file
--jq 'expression'Filter JSON dengan sintaks jq
--template 'tmpl'Format dengan Go template
--paginateAmbil semua halaman
-H 'Accept: ...'Set header kustom
Alias
Mengelola Alias
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
Alias Lanjutan
# Alias with shell command gh alias set --shell pv 'gh pr view --json url --jq .url | pbcopy' # Delete alias gh alias delete co
Tips Alias
gh alias set name 'cmd'Buat alias sederhana
--shellAlias berjalan via shell (mendukung pipe)
gh alias listTampilkan semua alias yang didefinisikan
gh alias delete nameHapus alias
Pola Umum
Alur Kerja Harian
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
Pencarian
gh search repos --language rust --stars ">1000" gh search issues --repo owner/repo "memory leak" gh search prs --state open --review required
Flag Berguna
--json field1,field2Output field tertentu sebagai JSON
--jq 'expr'Filter output JSON
-L NBatasi hasil ke N item
--webBuka hasil di browser
-R owner/repoTarget repository tertentu
GH_TOKEN=xxxAuth via environment variable