banner
Shelken

Shelken

twitter
github
jike

gh/glab コマンドの素早い使い方

![カバー](https://gcore.jsdelivr.net/gh/shelken/picbed@main/uPic/2024-01/6hNGCf.png)

目的#

  • gh または glab の公式 CLI ツールを使用して、GitHub または GitLab リポジトリを素早く作成する

インストール#

macOS#

brew install gh
brew install glab

コマンド#

認証#

gh auth login

iqb5Cp

ここで、必要なスコープのトークンを作成するためにtoken ページに移動してください。

glab auth login

oJfKuG

GitLab の場合、カスタムホスト名を選択できます(自己設定の場合)。

情報の表示#

# リポジトリ情報の一覧表示
gh repo list
glab repo list
## GitLabの場合、実行する前にホストを自己設定のものに設定してください。-gはグローバルオプションです。
glab config set -g host xxxx.xxxx.com


# 検索
## 名前がxxxのリポジトリを検索
glab repo search -s xxx


# プロジェクトのREADME情報を表示
gh repo view
glab repo view

リポジトリの作成と変更#

# 特定のリポジトリをクローンする

gh repo clone xxx/xxxx 
glab repo clone xxx/xxxx
glab repo clone https://xxxxx
glab repo clone [id]

# 作成
## gh
### この時点で、ディレクトリにtest-create-repoディレクトリがあり、test-create-repoはすでにgitリポジトリです。
### test-create-repoをプライベートとしてGitHubにプッシュすると、ghはリモートにtest-create-repoリポジトリを作成します。
gh repo create --private --source=test-create-repo --push

### test-repo-create2というプライベートリポジトリを作成し、以下の図のようにreadmeと説明を追加し、ローカルにクローンします。
gh repo create test-repo-create2 -c --private --add-readme -d "テストリモートリポジトリの作成とローカルへのクローン"

## glab
### 個人スペースにプライベートリポジトリを作成します。createの後には、パスと現在のディレクトリ内のディレクトリが続きます。
glab repo create test-create-repo --private -n test-create-repo -d "個人スペースにプライベートリポジトリを作成するテスト"
### グループ/スペースを指定する
glab repo create test-create-repo -n test-create-repo -g xxx -d "xxxグループにリポジトリを作成するテスト"



# リポジトリの可視性の変更
## 現在のディレクトリに対応するリポジトリをパブリックに変更する
gh repo edit --visibility public
## 指定したリポジトリの可視性をプライベートに変更する
gh repo edit shelken/test-create-repo --visibility private


# 削除
gh repo delete --yes
gh repo delete xxx/xxxx --yes

## スペース/リポジトリを指定して削除する
glab repo delete xxx/xxxx -y
## 自分/リポジトリを指定して削除する
glab repo delete xxxx -y
## 現在のディレクトリに対応するリポジトリを削除する
glab repo delete -y

VdIPIR

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。