Configuração
Instalação
brew install ghmacOS via Homebrew
sudo apt install ghDebian / Ubuntu
winget install GitHub.cliWindows via winget
conda install ghVia conda-forge
Autenticação
gh auth login # interactive login gh auth login --with-token < token.txt gh auth status # check auth state gh auth refresh -s repo,gist # add scopes
Configuração
gh config set editor vim gh config set pager less gh config set git_protocol ssh gh config list
Repositórios
Comandos de Repositório
gh repo create my-app --public --clone gh repo clone owner/repo gh repo fork owner/repo --clone gh repo view owner/repo --web
Opções de Repositório
--public | --privateDefinir visibilidade do repositório
--template owner/repoCriar a partir de repositório template
--cloneClonar após criar
--add-readmeInicializar com README
gh repo list ownerListar repositórios do owner
gh repo delete owner/repoExcluir repositório (com confirmação)
gh repo rename new-nameRenomear repositório atual
gh repo archive owner/repoArquivar um repositório
Issues
Gerenciando Issues
gh issue create --title "Bug" --body "Details here" gh issue list --state open --label bug gh issue view 42 gh issue close 42 --reason completed
Opções de Issue
--assignee @meAtribuir a si mesmo
--label bug,urgentAdicionar labels
--milestone v2.0Definir milestone
--project "Board"Adicionar ao projeto
gh issue edit 42Editar issue interativamente
gh issue reopen 42Reabrir issue fechada
gh issue comment 42 -b "msg"Adicionar comentário à issue
gh issue pin 42Fixar issue no repositório
Pull Requests
Criar e Gerenciar PRs
gh pr create --title "feat: add auth" --body "..." gh pr create --fill # title/body from commits gh pr list --state open gh pr view 123 --web
Revisar e Fazer Merge
gh pr checkout 123 # check out PR branch gh pr diff 123 # view PR diff gh pr review 123 --approve gh pr merge 123 --squash --delete-branch
Opções de PR
--draftCriar como PR draft
--reviewer user1,user2Solicitar revisores
--base mainDefinir branch base
--merge | --squash | --rebaseEstratégia de merge
--autoHabilitar auto-merge quando checks passam
--delete-branchExcluir branch após merge
gh pr ready 123Marcar PR draft como pronto
Actions
Comandos de Workflow
gh run list # recent runs gh run view 12345 # run details gh run view 12345 --log-failed # failed step logs gh run watch 12345 # live status
Acionar e Gerenciar
gh workflow run deploy.yml --ref main gh workflow list gh workflow view deploy.yml gh run rerun 12345 --failed # rerun failed jobs
Opções de Actions
-f key=valuePassar input para workflow_dispatch
--jsonSaída como JSON
-b branchFiltrar por branch
gh run download 12345Baixar artefatos da execução
gh cache listListar caches do Actions
gh cache delete KEYExcluir uma entrada de cache
Releases
Gerenciando Releases
gh release create v1.0.0 --generate-notes gh release create v1.0.0 ./dist/*.tar.gz gh release list gh release view v1.0.0
Opções de Release
--title "Release v1.0"Definir título da release
--notes "Changelog here"Definir notas de release inline
--notes-file CHANGELOG.mdNotas de arquivo
--generate-notesGerar automaticamente a partir de commits
--draftCriar como draft
--prereleaseMarcar como pré-release
--latestMarcar como release mais recente
gh release download v1.0.0Baixar assets da release
gh release delete v1.0.0Excluir uma release
gh release edit v1.0.0Editar metadados da release
Gists
Comandos de Gist
gh gist create file.py -d "My snippet" gh gist create file1.js file2.js # multi-file gist gh gist list gh gist view
Opções de Gist
-d "description"Definir descrição do gist
--publicCriar gist público (padrão: secreto)
--webAbrir gist no navegador
gh gist edit <id>Editar arquivos do gist
gh gist clone <id>Clonar gist localmente
gh gist delete <id>Excluir um gist
API
Fazendo Chamadas de API
gh api repos/owner/repo gh api repos/owner/repo/issues --method POST \ -f title="Bug" -f body="Details" gh api graphql -f query='{ viewer { login } }'
Formatando Saída
gh api repos/owner/repo --jq '.stargazers_count' gh api repos/owner/repo --template '{{.full_name}}' gh pr list --json number,title --jq '.[].title'
Opções de API
--method GET|POST|PUT|DELETEMétodo HTTP
-f key=valueDefinir campo string
-F key=@fileDefinir campo a partir de arquivo
--jq 'expression'Filtrar JSON com sintaxe jq
--template 'tmpl'Formatar com template Go
--paginateBuscar todas as páginas
-H 'Accept: ...'Definir header personalizado
Aliases
Gerenciando Aliases
gh alias set co 'pr checkout' gh alias set bugs 'issue list --label bug' gh alias set last 'run list -L 1' gh alias list
Aliases Avançados
# Alias with shell command gh alias set --shell pv 'gh pr view --json url --jq .url | pbcopy' # Delete alias gh alias delete co
Dicas de Alias
gh alias set name 'cmd'Criar alias simples
--shellAlias executa via shell (suporta pipes)
gh alias listMostrar todos os aliases definidos
gh alias delete nameRemover um alias
Padrões Comuns
Fluxo Diário
gh issue list --assignee @me # my open issues gh pr status # PRs needing attention gh pr checks 123 # CI status for PR gh run list -b main -L 5 # recent CI runs
Buscando
gh search repos --language rust --stars ">1000" gh search issues --repo owner/repo "memory leak" gh search prs --state open --review required
Flags Úteis
--json field1,field2Saída de campos específicos como JSON
--jq 'expr'Filtrar saída JSON
-L NLimitar resultados a N itens
--webAbrir resultado no navegador
-R owner/repoDirecionar para repositório específico
GH_TOKEN=xxxAuth via variável de ambiente