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?

【公ド読】コマンド ラインでの GitHub Copilot の使用

Last updated at Posted at 2025-05-10

【公式ドキュメントを読もうシリーズ】コマンド ラインでの GitHub Copilot の使用

シリーズ概要

https://qiita.com/yasu_programming/items/cec66f9e8d5d571e9ce3

URL

https://docs.github.com/ja/copilot/using-github-copilot/using-github-copilot-in-the-command-line

説明

コマンドラインでGithub Copilotを使用する方法が書かれている。
手順は下記の通りです。

手順

  1. ghコマンドのインストール
  2. Github CLIにログイン
  3. Copilot in the CLI 拡張機能のインストール
  4. コマンドラインでのGithub Copilotを試してみる

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

そもそもなんでghコマンドというコマンドをインストールするのかというと、コマンドラインでGithub Copilotを使用するうえで必要だからです(そりゃそうか)。
gh はgithub の略なのだろう。
これも公式のドキュメントありました。
https://docs.github.com/ja/github-cli/github-cli/about-github-cli

私はubuntuで触っていたので、こちらのリンクhttps://github.com/cli/cli/blob/trunk/docs/install_linux.mdのコマンドを叩いて、ghコマンドをインストールしました。
公式ドキュメントからのリンクですので、それぞれの環境に応じたghコマンドのインストール方法を探してください。

Github CLIにログイン

ログイン方法も公式リンクhttps://docs.github.com/ja/copilot/managing-copilot/configure-personal-settings/installing-github-copilot-in-the-cliから飛ぶことができます。

gh auth login
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account? Githubの公開鍵のパス
? Title for your SSH key: Githubの秘密鍵のパス
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: ****-****
Press Enter to open https://github.com/login/device in your browser...

Press Enterすると、Github のログイン画面に遷移し、codeを入力すると、ログイン完了になる。

Copilot in the CLI 拡張機能のインストール

公式ドキュメントに沿って、インストールしてみる。

$ gh extension install github/gh-copilot
✓ Installed extension github/gh-copilot

$ gh extension upgrade gh-copilot
[copilot]: already up to date
✓ Successfully checked extension upgrades

できた模様。

コマンドラインでのGithub Copilotを試してみる

公式ドキュメントのコマンド叩いてみる。

$ gh copilot explain "sudo apt-get"

? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> Yes

Welcome to GitHub Copilot in the CLI!
version 1.1.0 (2025-02-10)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency

Explanation:

  • sudo is used to run a command with elevated rights, allowing changes to system files.
  • apt-get is a command-line tool for handling packages in Debian-based systems, such as Ubuntu.
  • Available sub-commands include:
    • update to refresh the list of available packages.
    • upgrade to upgrade installed packages to their latest versions.
    • install to install a new package.
    • remove to uninstall a package.
    • autoremove to remove packages that were automatically installed to satisfy dependencies for other packages and are no longer
    needed.
  • You can leverage apt-get --help for more information on available options and usage.

答えてくれた。

日本語入れたらあんまり答えてもらえないみたい(2025年5月10日現在)。
フィードバックしたら、改善するみたいですので、フィードバックしたほうが良いのかもしれない。

$ gh copilot explain "github cliでできることを教えてほしい"

Welcome to GitHub Copilot in the CLI!
version 1.1.0 (2025-02-10)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency

Explanation not readily available. Please revise for better results.

--helpで何できるか聞いてみた。

gh copilot --help
Your AI command line copilot.

Usage:
  copilot [command]

Examples:

$ gh copilot suggest "Install git"
$ gh copilot explain "traceroute github.com"


Available Commands:
  alias       Generate shell-specific aliases for convenience
  config      Configure options
  explain     Explain a command
  suggest     Suggest a command

Flags:
  -h, --help              help for copilot
      --hostname string   The GitHub host to use for authentication
  -v, --version           version for copilot

Use "copilot [command] --help" for more information about a command.

いろいろ試したいね。

所感

gh copilotコマンドいろいろできそうだったので、alias config explain suggest試したいです。
コードに個人情報が含まれていないか、確認するのが、地味に大変だなと思った。

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?