gh 使用

安装

Ubuntu

(type -p wget >/dev/null || (sudo apt update && sudo apt-get 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 \
    && 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

macOS

brew install gh

参考:cli/cli: GitHub’s official command line tool

使用

gh auth login                                        # 登录

gh repo clone owner/repo                             # 克隆仓库
gh repo create <repo-name>                           # 新建仓库
gh repo view                                         # 查看当前目录对应的 GitHub 仓库信息

gh issue list                                        # 查看 issue 列表
gh issue create                                      # 创建 issue
gh issue view <issue-number>                         # 查看 issue
gh issue comment <issue-number> --body "my comment"  # 评论 issue
gh issue close <issue-number>                        # 关闭 issue

gh pr list                                           # 查看 PR 列表
gh pr create                                         # 创建 PR
gh pr merge <pr-number>                              # 合并 PR
gh pr view <pr-number>                               # 查看 PR 详情
gh pr --help                                         # 查看命令帮助
gh help                                              # 查看帮助
posted @ 2025-06-06 21:02  Undefined443  阅读(15)  评论(0)    收藏  举报