0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub Cli入門

Last updated at Posted at 2023-08-06

参考記事

  • GitHub CLIで始める快適GitHub生活

  • GitHub公式ドキュメント

今回の構築環境

  • Ubuntu 22.04.2 LTS

Ubuntu上ではlsb_release -aコマンドを実行すると、ディストリビューションのバージョンやコードネームを確認することができます。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

Linux環境バージョン確認方法について

インストール手順

  • GitCliをLinux環境にインストール
sudo apt install gh

認証

GitHub Cliを利用する前に自分のGitHubアカウントと連携するための認証が必要。
gh auth loginコマンドを実行して、認証を済ませてください。
※自分は下記内容で認証しました。

$ gh auth login
# どのアカウントにログインしますか?
What account do you want to log into? => GitHub.com
# Git操作に優先するプロトコルはなんですか?
What is your preferred protocol for Git operations? => SSH
# SSH 公開キーを GitHub アカウントにアップロードしますか?
Upload your SSH public key to your GitHub account? => 自身のSSH公開鍵
# GitHub CLI をどのように認証しますか?
How would you like to authenticate GitHub CLI? => Login with a web browser

https://github.com/login/device にアクセスし、ワンタイムパスワードでログイン後、認証を行う
image.png

GitCliを使ってリモートリポジトリを作成

  • ローカルディレクトリの情報をリモートリポジトリに追加する場合
    1. cdコマンドでプッシュしたいディレクトリへ移動
    2. git initコマンドを実行
    3. gh repo create リポジトリ名(任意) --private --source=pushするディレクトリパス(任意) --remote=upstreamを実行
    	# 現在のカレントディレクトリからリモートリポジトリを作成する
    	gh repo create test-cli --private --source=. --remote=upstream
    

なぜ、gh repo create test-cli --private --source=. --remote=upstreamを実行することで、リモートリポジトリにローカルディレクトリを追加することができるのかはわからない。
公式の gh repo create のオプション説明を見ても --source--remote=upstreamの十分な説明を見つけることができなかったため、知っている方がいれば教えてください。

  • リモートリポジトリが追加されているか確認
git remote -v
upstream        git@github.com:ユーザー名/リポジトリ名.git (fetch)
upstream        git@github.com:ユーザー名/リポジトリ名.git (push)
  • リモートリポジトリをブラウザで表示

gh browse
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?