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 です。

導入brew · apt · winget
認証gh auth login
協業clone · issue · pr
installauth loginclone / issue / pr

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 で確認。

インストール

  1. 1
    macOS

    brew install gh。

  2. 2
    Linux

    公式 apt 源のあと sudo apt install gh、Fedora は dnf install gh。

  3. 3
    Windows

    winget install GitHub.cli。

  4. 4
    PATH

    コマンドが見つからない場合は PATH を確認。

gh auth login

gh auth login
# GitHub.com → ブラウザログイン(推奨)または PAT 貼り付け
gh auth status

gh repo clone

gh repo clone cli/cli
gh repo clone owner/repo my-folder
gh repo clone owner/repo -- --depth=1

gh issue create

gh issue create --title "Fix timeout" --body "…"
gh issue create --label documentation --assignee @me

gh pr create

  1. 1
    push

    git push -u origin branch。

  2. 2
    PR

    gh pr create --title "…" --body "…" または対話式。

  3. 3
    オプション

    --draft、--reviewer、--base main。

目的ghgit / Web
clonegh repo clone owner/repogit clone
Issuegh issue createWeb Issues
PRgh pr createCompare & PR
auth login 失敗?

PAT 貼り付け、プロキシ、SSO 承認を確認。cli.github.com のトラブルシュート。

gh clone 必須?

いいえ。GitHub remote があれば git clone 済みでも issue/pr は使えます。

Desktop との使い分け?

GUI は Desktop、脚本と日常操作は gh。認証は別管理。

PR の要点を図に

スペースの作り方。

今すぐ開始