SOLFIND
Web Lens
Portal home

GitHub CLI | Take GitHub to the command line

https://cli.github.com/manual/gh_api • 109 KB fetched
Open original page


GitHub CLI | Take GitHub to the command line Skip to content CLI Copilot CLI Manual Release notes * Getting started * gh * agent-task * create * list * view * alias * delete * import * list * set * api * attestation * download * trusted-root * verify * auth * login * logout * refresh * setup-git * status * switch * token * browse * cache * delete * list * codespace * code * cp * create * delete * edit * jupyter * list * logs * ports * ports forward * ports visibility * rebuild * ssh * stop * view * completion * config * clear-cache * get * list * set * copilot * discussion * comment * create * edit * list * view * extension * browse * create * exec * install * list * remove * search * upgrade * gist * clone * create * delete * edit * list * rename * view * gpg-key * add * delete * list * help * environment * exit-codes * formatting * mintty * reference * telemetry * issue * close * comment * create * delete * develop * edit * list * lock * pin * reopen * status * transfer * unlock * unpin * view * label * clone * create * delete * edit * list * licenses * org * list * pr * checkout * checks * close * comment * create * diff * edit * list * lock * merge * ready * reopen * revert * review * status * unlock * update-branch * view * preview * prompter * project * close * copy * create * delete * edit * field-create * field-delete * field-list * item-add * item-archive * item-create * item-delete * item-edit * item-list * link * list * mark-template * unlink * view * release * create * delete-asset * delete * download * edit * list * upload * verify-asset * verify * view * repo * archive * autolink * autolink create * autolink delete * autolink list * autolink view * clone * create * delete * deploy-key * deploy-key add * deploy-key delete * deploy-key list * edit * fork * gitignore * gitignore list * gitignore view * license * license list * license view * list * read-dir * read-file * rename * set-default * sync * unarchive * view * ruleset * check * list * view * run * cancel * delete * download * list * rerun * view * watch * search * code * commits * issues * prs * repos * secret * delete * list * set * skill * install * list * preview * publish * search * update * ssh-key * add * delete * list * status * variable * delete * get * list * set * workflow * disable * enable * list * run * view CLI manual * Getting started * gh * agent-task * create * list * view * alias * delete * import * list * set * api * attestation * download * trusted-root * verify * auth * login * logout * refresh * setup-git * status * switch * token * browse * cache * delete * list * codespace * code * cp * create * delete * edit * jupyter * list * logs * ports * ports forward * ports visibility * rebuild * ssh * stop * view * completion * config * clear-cache * get * list * set * copilot * discussion * comment * create * edit * list * view * extension * browse * create * exec * install * list * remove * search * upgrade * gist * clone * create * delete * edit * list * rename * view * gpg-key * add * delete * list * help * environment * exit-codes * formatting * mintty * reference * telemetry * issue * close * comment * create * delete * develop * edit * list * lock * pin * reopen * status * transfer * unlock * unpin * view * label * clone * create * delete * edit * list * licenses * org * list * pr * checkout * checks * close * comment * create * diff * edit * list * lock * merge * ready * reopen * revert * review * status * unlock * update-branch * view * preview * prompter * project * close * copy * create * delete * edit * field-create * field-delete * field-list * item-add * item-archive * item-create * item-delete * item-edit * item-list * link * list * mark-template * unlink * view * release * create * delete-asset * delete * download * edit * list * upload * verify-asset * verify * view * repo * archive * autolink * autolink create * autolink delete * autolink list * autolink view * clone * create * delete * deploy-key * deploy-key add * deploy-key delete * deploy-key list * edit * fork * gitignore * gitignore list * gitignore view * license * license list * license view * list * read-dir * read-file * rename * set-default * sync * unarchive * view * ruleset * check * list * view * run * cancel * delete * download * list * rerun * view * watch * search * code * commits * issues * prs * repos * secret * delete * list * set * skill * install * list * preview * publish * search * update * ssh-key * add * delete * list * status * variable * delete * get * list * set * workflow * disable * enable * list * run * view gh api gh api <endpoint> [flags] Makes an authenticated HTTP request to the GitHub API and prints the response. The endpoint argument should either be a path of a GitHub API v3 endpoint, or graphql to access the GitHub API v4. Placeholder values {owner} , {repo} , and {branch} in the endpoint argument will get replaced with values from the repository of the current directory or the repository specified in the GH_REPO environment variable. Note that in some shells, for example PowerShell, you may need to enclose any value that contains {...} in quotes to prevent the shell from applying special meaning to curly braces. The -p/--preview flag enables opting into previews, which are feature-flagged, experimental API endpoints or behaviors. The API expects opt-in via the Accept header with format application/vnd.github.<preview-name>-preview+json and this command facilitates that via --preview <preview-name> . To send a request for the corsair and scarlet witch previews, you could use -p corsair,scarlet-witch or --preview corsair --preview scarlet-witch . The default HTTP request method is GET normally and POST if any parameters were added. Override the method with --method . Pass one or more -f/--raw-field values in key=value format to add static string parameters to the request payload. To add non-string or placeholder-determined values, see -F/--field below. Note that adding request parameters will automatically switch the request method to POST . To send the parameters as a GET query string instead, use --method GET . The -F/--field flag has magic type conversion based on the format of the value: * literal values true , false , null , and integer numbers get converted to appropriate JSON types; * placeholder values {owner} , {repo} , and {branch} get populated with values from the repository of the current directory; * if the value starts with @ , the rest of the value is interpreted as a filename to read the value from. Pass - to read from standard input. For GraphQL requests, all fields other than query and operationName are interpreted as GraphQL variables. To pass nested parameters in the request payload, use key[subkey]=value syntax when declaring fields. To pass nested values as arrays, declare multiple fields with the syntax key[]=value1 , key[]=value2 . To pass an empty array, use key[] without a value. To pass pre-constructed JSON or payloads in other formats, a request body may be read from file specified by --input . Use - to read from standard input. When passing the request body this way, any parameters specified via field flags are added to the query string of the endpoint URL. In --paginate mode, all pages of results will sequentially be requested until there are no more pages of results. For GraphQL requests, this requires that the original query accepts an $endCursor: String variable and that it fetches the pageInfo{ hasNextPage, endCursor } set of fields from a collection. Each page is a separate JSON array or object. Pass --slurp to wrap all pages of JSON arrays or objects into an outer JSON array. Options --allow-escape-sequences Allow printing terminal escape sequences --cache <duration> Cache the response, e.g. "3600s", "60m", "1h" -F , --field <key=value> Add a typed parameter in key=value format (use "@<path>" or "@-" to read value from file or stdin) -H , --header <key:value> Add a HTTP request header in key:value format --hostname <string> The GitHub hostname for the request (default "github.com") -i , --include Include HTTP response status line and headers in the output --input <file> The file to use as body for the HTTP request (use "-" to read from standard input) -q , --jq <string> Query to select values from the response using jq syntax -X , --method <string> (default "GET") The HTTP method for the request --paginate Make additional HTTP requests to fetch all pages of results -p , --preview <strings> Opt into GitHub API previews (names should omit '-preview') -f , --raw-field <key=value> Add a string parameter in key=value format --silent Do not print the response body --slurp Use with "--paginate" to return an array of all pages of either JSON arrays or objects -t , --template <string> Format JSON output using a Go template; see "gh help formatting" --verbose Include full HTTP request and response in the output Examples # List releases in the current repository $ gh api repos/ { owner } / { repo } /releases # Post an issue comment $ gh api repos/ { owner } / { repo } /issues/123/comments -f body = 'Hi from CLI' # Post nested parameter read from a file $ gh api gists -F 'files[myfile.txt][content][email protected]' # Add parameters to a GET request $ gh api -X GET search/issues -f q = 'repo:cli/cli is:open remote' # Use a JSON file as request body $ gh api repos/ { owner } / { repo } /rulesets --input file.json # Set a custom HTTP header $ gh api -H 'Accept: application/vnd.github.v3.raw+json' ... # Opt into GitHub API previews $ gh api --preview baptiste,nebula ... # Print only specific fields from the response $ gh api repos/ { owner } / { repo } /issues --jq '.[].title' # Use a template for the output $ gh api repos/ { owner } / { repo } /issues --template \ '{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " | color "yellow"}}){{"\n"}}{{end}}' # Update allowed values of the "environment" custom property in a deeply nested array $ gh api -X PATCH /orgs/ { org } /properties/schema \ -F 'properties[][property_name]=environment' \ -F 'properties[][default_value]=production' \ -F 'properties[][allowed_values][]=staging' \ -F 'properties[][allowed_values][]=production' # List releases with GraphQL $ gh api graphql -F owner = '{owner}' -F name = '{repo}' -f query = ' query($name: String!, $owner: String!) { repository(owner: $owner, name: $name) { releases(last: 3) { nodes { tagName } } } } ' # List all repositories for a user $ gh api graphql --paginate -f query = ' query($endCursor: String) { viewer { repositories(first: 100, after: $endCursor) { nodes { nameWithOwner } pageInfo { hasNextPage endCursor } } } } ' # Get the percentage of forks for the current user $ gh api graphql --paginate --slurp -f query = ' query($endCursor: String) { viewer { repositories(first: 100, after: $endCursor) { nodes { isFork } pageInfo { hasNextPage endCursor } } } } ' | jq 'def count(e): reduce e as $_ (0;.+1); [.[].data.viewer.repositories.nodes[]] as $r | count(select($r[].isFork))/count($r[])' See also * gh Product * Features * Security * Enterprise * Customer stories * Pricing * Resources Platform * Developer API * Partners * GitHub Desktop * GitHub Mobile Support * Help * Community Forum * Expert Services * Status * Contact GitHub Company * About * Blog * Careers * Press * Shop * (c) 2026 GitHub, Inc. * Terms * Privacy * Telemetry * * * * *

Links found on this page

  1. Skip to content [direct]
  2. CLI [direct]
  3. Copilot CLI [direct]
  4. Manual [direct]
  5. Release notes [direct]
  6. Getting started [direct]
  7. gh [direct]
  8. agent-task [direct]
  9. create [direct]
  10. list [direct]
  11. view [direct]
  12. alias [direct]
  13. delete [direct]
  14. import [direct]
  15. list [direct]
  16. set [direct]
  17. attestation [direct]
  18. download [direct]
  19. trusted-root [direct]
  20. verify [direct]
  21. auth [direct]
  22. login [direct]
  23. logout [direct]
  24. refresh [direct]
  25. setup-git [direct]
  26. status [direct]
  27. switch [direct]
  28. token [direct]
  29. browse [direct]
  30. cache [direct]
  31. delete [direct]
  32. list [direct]
  33. codespace [direct]
  34. code [direct]
  35. cp [direct]
  36. create [direct]
  37. delete [direct]
  38. edit [direct]
  39. jupyter [direct]
  40. list [direct]
  41. logs [direct]
  42. ports [direct]
  43. ports forward [direct]
  44. ports visibility [direct]
  45. rebuild [direct]
  46. ssh [direct]
  47. stop [direct]
  48. view [direct]
  49. completion [direct]
  50. config [direct]
  51. clear-cache [direct]
  52. get [direct]
  53. list [direct]
  54. set [direct]
  55. copilot [direct]
  56. discussion [direct]
  57. comment [direct]
  58. create [direct]
  59. edit [direct]
  60. list [direct]
  61. view [direct]
  62. extension [direct]
  63. browse [direct]
  64. create [direct]
  65. exec [direct]
  66. install [direct]
  67. list [direct]
  68. remove [direct]
  69. search [direct]
  70. upgrade [direct]
  71. gist [direct]
  72. clone [direct]
  73. create [direct]
  74. delete [direct]
  75. edit [direct]
  76. list [direct]
  77. rename [direct]
  78. view [direct]
  79. gpg-key [direct]
  80. add [direct]