GitHub CLI(gh)のインストール:auth login、clone、Issue と Pull Request 作成
gh を入れ、認証・clone・Issue/PR をターミナルで完了する。
GitHub CLI(gh)でログイン、clone、Issue、Pull Request をターミナルから操作できます。本稿は macOS/Linux/Windows のインストール、gh auth login、gh repo clone、gh issue create、gh pr create を hereink 向けにまとめます。
検索語はGitHub CLI gh のインストールと auth login・clone・Issue・PR 作成。gh を入れ、GitHub.com に認証し、リポジトリを clone して Issue/PR を 1 本ずつ作れれば OK です。
gh が解くこと
ターミナルから GitHub
gh repo clone、gh issue list、gh pr create を git と同じ画面で。
git と役割分担
コミットは git、PR メタデータは gh。
公式:
github.com/cli/cli、cli.github.com。gh --versionで確認。
インストール
- 1macOS
brew install gh。 - 2Linux
公式 apt 源のあと
sudo apt install gh、Fedora はdnf install gh。 - 3Windows
winget install GitHub.cli。 - 4PATH
コマンドが見つからない場合は PATH を確認。
gh auth login
gh auth login
# GitHub.com → ブラウザログイン(推奨)または PAT 貼り付け
gh auth statusgh repo clone
gh repo clone cli/cli
gh repo clone owner/repo my-folder
gh repo clone owner/repo -- --depth=1gh issue create
gh issue create --title "Fix timeout" --body "…"
gh issue create --label documentation --assignee @megh pr create
- 1push
git push -u origin branch。 - 2PR
gh pr create --title "…" --body "…"または対話式。 - 3オプション
--draft、--reviewer、--base main。
| 目的 | gh | git / Web |
|---|---|---|
| clone | gh repo clone owner/repo | git clone |
| Issue | gh issue create | Web Issues |
| PR | gh pr create | Compare & PR |
auth login 失敗?
PAT 貼り付け、プロキシ、SSO 承認を確認。cli.github.com のトラブルシュート。
gh clone 必須?
いいえ。GitHub remote があれば git clone 済みでも issue/pr は使えます。
Desktop との使い分け?
GUI は Desktop、脚本と日常操作は gh。認証は別管理。