Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

gh

The GitHub CLI: pull requests, Actions runs, issues, releases, secrets and the API — from the terminal.

Niveau
DevSecOps-service
Groep
Git en CI/CD
Root nodig
Nee
Pakket
gh

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

gh logs in to GitHub once (gh auth login) and then works with the repo of the current folder. You can open and review pull requests, watch and re-run GitHub Actions workflows, read logs, set repository secrets, create releases and call the REST or GraphQL API (gh api). It is also installed on GitHub-hosted runners, so pipelines use it with GH_TOKEN.

Zo schrijf je het

gh COMMAND SUBCOMMAND [FLAGS]
gh api ENDPOINT [-X METHOD] [-f key=value]

Belangrijkste delen

Commands

auth login / status
Log in / check the login.
repo clone|create|view|fork
Repositories.
pr create|list|view|checkout|review|merge
Pull requests.
issue create|list|view|close
Issues.
run list|view|watch|rerun
GitHub Actions runs.
workflow list|run|enable|disable
Workflows.
secret set|list|delete
Actions secrets.
variable set|list
Actions variables.
release create|list|download
Releases.
api ENDPOINT
Call the REST or GraphQL API.
attestation verify
Check build provenance of an artifact.
ruleset list|view
Repository rules.

Opties 5

Meest gebruikt

Common flags

-R OWNER/REPO
Use another repository.
--json FIELDS / --jq EXPR
JSON output and filter.
-w, --web
Open in the browser.
--paginate
All pages (api).
-X METHOD / -f k=v / -F k=@file
API method and fields.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Log in and check

    gh auth login
    gh auth status
  2. 2Open a pull request from your branch

    git push -u origin feat/add-health-check
    gh pr create --title "Add /health endpoint" --body "Adds a health check for the load balancer." --base main
    gh pr view --web
  3. 3Review and check out a colleague's PR

    gh pr list
    gh pr checkout 42
    gh pr diff 42
    gh pr review 42 --approve -b "Looks good"
  4. 4Watch a workflow run and read failed logs

    gh run list --limit 5
    gh run watch
    gh run view --log-failed
    gh run rerun 9483721055 --failed
  5. 5Start a workflow by hand

    gh workflow run deploy.yml -f environment=staging
  6. 6Set a secret for Actions

    gh secret set AZURE_CLIENT_ID --body "00000000-0000-0000-0000-000000000000"
    gh secret set KUBECONFIG < ~/.kube/lab.config
    gh secret list
  7. 7Make a release with files

    gh release create v1.4.0 dist/*.tar.gz --title "Shop 1.4.0" --notes-file CHANGELOG.md
  8. 8Call the API

    gh api repos/s0sta/platform/pulls?state=open --jq '.[].title'
    gh api repos/s0sta/platform/branches/main/protection
    gh api --paginate orgs/myorg/repos --jq '.[].full_name'
  9. 9Check Dependabot and code-scanning alerts

    gh api repos/s0sta/platform/dependabot/alerts --jq '.[] | [.security_advisory.severity, .dependency.package.name] | @tsv'
    gh api repos/s0sta/platform/code-scanning/alerts --jq '.[].rule.id'
  10. 10Verify that an artifact was built by your pipeline

    gh attestation verify shop.tar.gz --owner s0sta
  11. 11Use gh inside a workflow

    cat .github/workflows/label.yml
        steps:
          - run: gh pr edit ${{ github.event.number }} --add-label "needs-review"
            env:
              GH_TOKEN: ${{ github.token }}

Let op

  • gh auth token prints your token; never paste it into logs or chats.
  • Give CI tokens the smallest permissions: they need.

Bestanden

~/.config/gh/hosts.yml
Login data.
~/.config/gh/config.yml
Settings and aliases.

Tips om te onthouden

  • gh alias set prs 'pr list --author @me' makes short commands.

Exitcodes

0Success.
1Error.
4Login needed.