ข้ามไปเนื้อหาหลัก

Category: reference

GitHub CLI (gh) — จัดการ GitHub จาก Terminal ได้เลย

คู่มือใช้ gh CLI สำหรับ PR, Issues, Actions และ workflow automation โดยไม่ต้องเปิด browser

· อ่านประมาณ 1 นาที

สารบัญ

ติดตั้งและ Login

# ติดตั้ง
brew install gh          # macOS
winget install GitHub.cli # Windows
sudo apt install gh       # Ubuntu/Debian

# Login
gh auth login            # เปิด browser ให้ authenticate
gh auth status           # ตรวจสอบ status

Pull Request

# สร้าง PR จาก branch ปัจจุบัน
gh pr create --title "feat: add dark mode" --body "Description here"
gh pr create --draft                        # draft PR
gh pr create --assignee @me

# List และ checkout
gh pr list
gh pr list --state closed
gh pr checkout 42        # checkout PR #42 locally

# Review
gh pr view 42
gh pr diff 42
gh pr review 42 --approve
gh pr review 42 --request-changes --body "Please fix X"

# Merge
gh pr merge 42 --squash  # squash merge
gh pr merge 42 --rebase

Issues

gh issue create --title "Bug: X is broken" --label bug
gh issue list --assignee @me
gh issue close 15 --comment "Fixed in #42"
gh issue view 15

GitHub Actions

gh run list              # รายการ workflow run ล่าสุด
gh run view 12345        # ดูผล run
gh run watch             # รอ run ปัจจุบันและ stream output
gh run rerun 12345       # rerun ที่ failed
gh workflow list
gh workflow run deploy.yml --field env=production

Repository

gh repo clone owner/repo
gh repo fork owner/repo
gh repo create my-project --public --clone
gh repo view              # เปิด browser ดู repo

Release

gh release create v1.0.0 --title "v1.0.0" --notes "Release notes"
gh release create v1.0.0 dist/*.zip  # แนบ assets
gh release list

Tips

# เปิด browser ที่หน้าปัจจุบัน
gh browse

# ค้นหา issue/PR ด้วย jq
gh issue list --json title,number | jq '.[] | select(.title | contains("bug"))'

# Alias สำหรับ command ที่ใช้บ่อย
gh alias set prc 'pr create --fill'