文章

安装github的gh命令

浏览: 14评论: 0发布时间: 2026-01-17

mac电脑

# 使用 Homebrew
brew install gh

windows

# 使用 winget
winget install GitHub.cli
 
# 或者使用 Scoop
scoop install gh
 
# 或者使用 Chocolatey
choco install gh

登录命令

gh auth login

然后按提示操作:

? What account do you want to log into?
> GitHub.com          # 选择这个
  GitHub Enterprise Server

? What is your preferred protocol for Git operations?
> HTTPS              # 一般选 HTTPS
  SSH

? Authenticate Git with your GitHub credentials?
> Yes                # 选 Yes

? How would you like to authenticate GitHub CLI?
> Login with a web browser    # 推荐:浏览器登录
  Paste an authentication token

选择浏览器登录后:

复制终端显示的一次性代码
按 Enter 打开浏览器
粘贴代码并授权

验证是否成功

# 查看登录状态
gh auth status

# 应该显示类似:
# ✓ Logged in to github.com as your-username