0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2にて、GitHub CLIを使う方法

Last updated at Posted at 2025-10-15

前書き

手間取ったので共有

本題

1

Installing gh on Linux and BSDにあるように以下のコマンドを実行する。

(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
	&& sudo mkdir -p -m 755 /etc/apt/keyrings \
	&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
	&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
	&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
	&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
	&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
	&& sudo apt update \
	&& sudo apt install gh -y
sudo apt update
sudo apt install gh

2

gh auth loginでブラウザでログインする場合は以下のコマンドを行う。

sudo apt install -y wslu
echo ":WSLInterop:M::MZ::/init:PF" | sudo tee /usr/lib/binfmt.d/WSLInterop.conf

念のためWindows側で一旦、Ubuntuを落とす。(理由

wsl --shutdown

再度、Ubuntuに入る。

3

gh auth status

「Login with a web browser」でログインするときに必要なコードはターミナル上に表示されている。

ログインできたかどうかは以下のコマンドで分かる。

gh auth status

参考にしたサイト

その他

SSH Keyの生成とアップロードをすることもできる。


クローンするときは

gh repo clone https://github.com/xxx/xxx.git

でやると勝手に認証関係をやってくれるので楽。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?