LoginSignup
11
9

More than 1 year has passed since last update.

Ubuntu に gh コマンド (GitHub CLI) をインストールする

Last updated at Posted at 2021-12-07

GitHub CLI である gh コマンドをインストールする手順です。

gh コマンドのインストール

公式のインストール手順を参考にインストールします。

type -p curl >/dev/null || sudo apt install curl -y
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/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

gh を起動してみます。

❯ gh --version
gh version 2.17.0 (2022-10-04)
https://github.com/cli/cli/releases/tag/v2.17.0

gh コマンドの使い方

gh コマンドの簡単な使い方をご紹介します。

まずは、 login の認証を行います。

❯ gh auth login

リポジトリをクローンする。

❯ gh repo clone cli/cli

gh コマンド を補完する (completion)

サブコマンドの補完が利いて便利です。
bash の場合、下記を .bashrc に追記すればOKです。
(zsh, fish, PowerShell にも対応してます)

eval "$(gh completion -s bash)"

gh <Tab><Tab> にてサブコマンドが表示されます。

❯ gh
alias       (Create command shortcuts)
api         (Make an authenticated GitHub API request)
auth        (Authenticate gh and git with GitHub)
browse      (Open the repository in the browser)
co          (Alias for pr checkout)
codespace   (Connect to and manage codespaces)
completion  (Generate shell completion scripts)
config      (Manage configuration for gh)
extension   (Manage gh extensions)
gist        (Manage gists)
gpg-key     (Manage GPG keys)
help        (Help about any command)
issue       (Manage issues)
label       (Manage labels)
pr          (Manage pull requests)
release     (Manage releases)
repo        (Manage repositories)
run         (View details about workflow runs)
search      (Search for repositories, issues, and pull requests)
secret      (Manage GitHub secrets)
ssh-key     (Manage SSH keys)
status      (Print information about relevant issues, pull requests, and notifications acr…)
workflow    (View details about GitHub Actions workflows)

参考

11
9
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
11
9