GitHub CLI
Operar GitHub desde el terminal
gh (GitHub CLI) es la herramienta oficial de línea de comandos para GitHub: issues, pull requests, releases, gists y la API de GitHub sin salir del terminal.
🔑 Autenticación
Sección titulada «🔑 Autenticación»gh auth login # iniciar sesión (navegador o token)gh auth status # ver estado de autenticacióngh auth token # imprimir el token usadogh auth logout # cerrar sesión📦 Comandos de repositorio
Sección titulada «📦 Comandos de repositorio»gh repo create mi-proyecto --public --clone # crear repo y clonargh repo clone <propietario>/<repo> # clonar (mantiene remotos)gh repo view <propietario>/<repo> # ver detalles y URLgh repo fork <repo> --clone # fork y clonar🔀 Pull requests
Sección titulada «🔀 Pull requests»gh pr create --base main --title "feat: login" --body "Descripción" # abrir PRgh pr create --draft # PR en borradorgh pr checkout 123 # cambiar a una PR existente (crea rama)gh pr view 123 # ver PRgh pr diff 123 # ver el diffgh pr review 123 --approve # aprobargh pr review 123 --comment --body "Comentario" # comentargh pr checks 123 # ver estado de los checks de CIgh pr merge 123 --squash --delete-branch # fusionar y limpiar rama🐛 Issues
Sección titulada «🐛 Issues»gh issue create --title "Bug: login" --body "Repro..." --label buggh issue list --label bug --assignee @megh issue view 42gh issue close 42 --reason completedgh issue comment 42 --body "Corregido en #50"🚀 Releases
Sección titulada «🚀 Releases»gh release create v1.0.0 dist/app.zip --title "v1.0.0" --notes "Cambios: ver CHANGELOG"gh release view v1.0.0gh release list --limit 10gh release download v1.0.0 --pattern "*.deb" # descargar artefactos🧩 Gists
Sección titulada «🧩 Gists»gh gist create script.py --public # crear gistgh gist list # listar los propiosgh gist view <id>gh gist edit <id> --add script2.py📊 Flujos de Actions y API
Sección titulada «📊 Flujos de Actions y API»gh run watch # seguir la ejecución del workflow actual en tiempo realgh run list --branch main --limit 10 # listar ejecuciones recientesgh run download <run-id> --dir ./artifacts # descargar artefactos
# gh api: acceso directo a la API REST de GitHubgh api repos/octocat/hello-world # GET de un repogh api /repos/{owner}/{repo}/pulls?state=open # listar PRs abiertos (JSON)gh api user -q .login # filtrar con jq (--jq equivale a -q)🧩 Extensiones e instalación
Sección titulada «🧩 Extensiones e instalación»gh extension install <propietario>/<ext> # instalar extensión comunitariagh extension list # ver extensiones instaladas
# Instalación de gh# macOS: brew install gh · Debian/Ubuntu: repos oficiales · Windows: winget install GitHub.cli🤖 GitHub CLI en CI (GH_TOKEN)
Sección titulada «🤖 GitHub CLI en CI (GH_TOKEN)»gh usa la variable de entorno GH_TOKEN para autenticarse sin pasos interactivos:
en GitHub Actions ya viene con el token GITHUB_TOKEN.
steps: - uses: actions/checkout@v4 - name: Publicar release run: gh release create v1.0.0 dist/app.zip env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}❓ gh autentica también mis pulsos de git push?
➡ Con gh auth login (y gh auth setup-git) GitHub CLI configura el credencial helper para HTTP para todo Git.
❓ Puedo usar gh sin instalar nada en CI?
➡ GitHub Actions ya incluye gh; para otros CI instálalo o usa su binario.
❓ Qué hay de GitLab?
➡ gh es específico de GitHub. GitLab tiene glab (CLI similar, no está en esta colección).
🔗 Enlaces
Sección titulada «🔗 Enlaces»🧩 Ver también
Sección titulada «🧩 Ver también»Colección creada y mantenida por CeleroLab. Contenido libre bajo licencia MIT.