GitHub CLI
Gerencie pull requests, issues, repositórios e fluxos de trabalho diretamente do terminal com gh.
Busque em todas as páginas da documentação
Gerencie pull requests, issues, repositórios e fluxos de trabalho diretamente do terminal com gh.
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥
Cartão de receita de referência rápida - pronto para copiar e colar.
# Authenticate
gh auth login
# Create a pull request
gh pr create --title "feat: add auth page" --body "Adds login and signup forms"
# List open PRs
gh pr list
# Check out a PR locally
gh pr checkout 42
# Merge a PR
gh pr merge 42 --squash --delete-branch
# Create an issue
gh issue create --title "Bug: sidebar flickers" --label bug
# View repo in browser
gh browseQuando usar isso: Qualquer operação do GitHub que você normalmente faria no navegador - PRs, issues, releases, Actions.
# Full PR workflow from terminal
git checkout -b feature/search
# ... write code ...
git add src/components/Search.tsx src/app/search/page.tsx
git commit -m "feat: add search page with debounced input"
git push -u origin feature/search
# Create PR with body
gh pr create --title "feat: add search page" --body "## Summary
- Debounced search input with 300ms delay
- Server-side filtering via search params
- Loading skeleton during fetch
## Test plan
- [ ] Type in search box, verify debounce
- [ ] Check URL updates with search param
- [ ] Verify loading state appears"
# Check CI status
gh pr checks 42
# View PR diff
gh pr diff 42
# Merge when ready
gh pr merge 42 --squash --delete-branchO que isso demonstra:
--squash combina todos os commits em um único commit limpo no main--delete-branch limpa o branch remoto após o merge# Create PR (interactive - prompts for title, body, reviewers)
gh pr create
# Create PR with reviewers and labels
gh pr create --title "fix: resolve hydration error" \
--reviewer teammate1,teammate2 \
--label "bug,priority:high"
# Create draft PR
gh pr create --draft --title "WIP: new dashboard"
# List PRs with filters
gh pr list --state open --author @me
gh pr list --label "needs-review"
gh pr list --search "is:open draft:false"
# View PR details
gh pr view 42
gh pr view 42 --web # opens in browser
# Review a PR
gh pr checkout 42
gh pr review 42 --approve
gh pr review 42 --request-changes --body "Need to handle the loading state"
gh pr review 42 --comment --body "Looks good, minor suggestion on line 45"
# Merge options
gh pr merge 42 --merge # merge commit
gh pr merge 42 --squash # squash and merge
gh pr merge 42 --rebase # rebase and merge
gh pr merge 42 --auto --squash # auto-merge when checks pass
# Close without merging
gh pr close 42# Create issue (interactive)
gh issue create
# Create with labels and assignee
gh issue create \
--title "Add dark mode support" \
--body "Users have requested a dark mode toggle in settings." \
--label "enhancement,ui" \
--assignee @me
# List issues
gh issue list
gh issue list --label "bug" --state open
gh issue list --assignee @me
# View and manage
gh issue view 15
gh issue close 15
gh issue reopen 15
# Add a comment
gh issue comment 15 --body "Fixed in PR #42"
# Transfer issue to another repo
gh issue transfer 15 org/other-repo# Clone a repo
gh repo clone owner/repo
# Create a new repo
gh repo create my-app --private --clone
gh repo create my-app --public --template nextjs/template
# Fork a repo
gh repo fork owner/repo --clone
# View repo info
gh repo view
gh repo view owner/repo --web
# List your repos
gh repo list --language typescript --sort updated
# Set repo topics
gh repo edit --add-topic "nextjs,react,typescript"# List recent workflow runs
gh run list
# View a specific run
gh run view 12345
# Watch a run in progress
gh run watch 12345
# Re-run a failed job
gh run rerun 12345 --failed
# Trigger a workflow manually
gh workflow run deploy.yml --ref main
# List workflows
gh workflow list
gh workflow view deploy.yml# Create a release
gh release create v1.0.0 --title "v1.0.0" --notes "Initial release"
# Create release with auto-generated notes
gh release create v1.1.0 --generate-notes
# Create a draft release
gh release create v2.0.0-beta --draft --prerelease
# List releases
gh release list
# Download release assets
gh release download v1.0.0# Call any GitHub REST API endpoint
gh api repos/owner/repo/pulls/42/comments
# Create a comment via API
gh api repos/owner/repo/issues/15/comments \
-f body="Automated comment from CLI"
# GraphQL query
gh api graphql -f query='
query {
repository(owner: "vercel", name: "next.js") {
stargazerCount
description
}
}
'
# Paginate results
gh api repos/owner/repo/issues --paginate --jq '.[].title'Coisas que vão te morder. Cada armadilha inclui o que dá errado, por que acontece e a correção.
Problemas de escopo de autenticação - gh retorna erros 403 para certas operações. Correção: Reautentique com os escopos necessários: gh auth login --scopes repo,read:org.
Branch padrão incorreto - A PR tem como alvo o branch base errado. Correção: Especifique explicitamente: gh pr create --base main.
Auto-merge não habilitado - gh pr merge --auto falha silenciosamente. Correção: Habilite o auto-merge nas configurações do repositório primeiro (Settings > General > Allow auto-merge).
Checkout desatualizado - gh pr checkout não busca as alterações mais recentes se você já tem o branch. Correção: Execute git pull após o checkout, ou exclua o branch local primeiro.
Outras maneiras de resolver o mesmo problema - e quando cada uma é a melhor escolha.
| Alternativa | Use Quando | Não Use Quando |
|---|---|---|
| UI Web do GitHub | Revisões de PR complexas com comentários inline | Operações rápidas ou scripting |
CLI hub (legado) | Já incorporado em scripts existentes | Novos projetos - gh é o sucessor oficial |
| API do GitHub diretamente | Integrações personalizadas ou scripts de CI | Fluxos de trabalho focados no terminal |
| Extensão GitHub do VS Code | Você prefere uma GUI dentro do seu editor | Fluxos de trabalho focados no terminal |
gh auth logingh pr create --draft --title "WIP: new feature"gh pr ready 42--squash combina todos os commits em um único commit no branch de destino--merge cria um merge commit preservando todos os commits individuais--rebase reproduz commits individualmente em cima do branch de destino (histórico linear)gh pr checks 42gh pr checks 42 --watch para acompanhar em tempo realgh issue create --title "Bug: form validation" --assignee @me --label bug@me é um atalho para seu nome de usuário do GitHubgh api repos/owner/repo/pulls/42/comments
gh api graphql -f query='{ viewer { login } }'gh api lida com a autenticação automaticamentegh run rerun 12345 --failedgh pr checkout muda para ele sem fazer pullgit pull após o checkout para obter as alterações mais recentesgh pr create --base develop --title "feat: new feature"--base, a PR tem como alvo o branch padrão do repositório (geralmente main)gh pr create --title "fix: type error in utils" \
--reviewer teammate1 \
--label "bug,typescript"gh pr list --state open --author @me--repo owner/repo para limitar a um repositório específicoRevisado por Chris St. John·Última atualização: 19 de jul. de 2026
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥