="#2544bb"/> # Publish file 'hello.py' as a public gist $ gh gist create --public hello.py # Create a gist with a description $ gh gist create hello.py -d "my Hello-World program in Python" # Create a gist containing several files $ gh gist create hello.py world.py cool.txt # Create a gist containing several files using patterns $ gh gist create *.md *.txt artifact.* # Read from standard input to create a gist $ gh gist create - # Create a gist from output piped from another command $ cat cool.txt | gh gist create _ _ | | | | _|_ | | __, _ _ | | __ | |/ \ / | / |/ | |/_) | | / \_| | |_/| |_/\_/|_/ | |_/| \_/ \_/|/\__/ \_/|_/ /| \| _ o | | | __ __ _ _ _|_ ,_ | | _|_ __ ,_ , | / / \_/ |/ | | / | | |/ \_| | | / \_/ | / \_| \___/\__/ | |_/|_/ |_/|_/\_/ \_/|_/|_/\__/ |_/ \/ o Generate the autocompletion script for the bash shell. This script depends on the 'bash-completion' package. If it is not installed already, you can install it via your OS's package manager. To load completions in your current shell session: source <(%[1]s completion bash) To load completions for every new session, execute once: #### Linux: %[1]s completion bash > /etc/bash_completion.d/%[1]s #### macOS: %[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s You will need to start a new shell for this setup to take effect. # Display authentication status for all accounts on all hosts $ gh auth status # Display authentication status for the active account on a specific host $ gh auth status --active --hostname github.example.com # Display tokens in plain text $ gh auth status --show-token # Format authentication status as JSON $ gh auth status --json hosts # Include plain text token in JSON output $ gh auth status --json hosts --show-token # Format hosts as a flat JSON array $ gh auth status --json hosts --jq '.hosts | add' # Interactively choose a ruleset to view from all rulesets that apply to the current repository $ gh ruleset view # Interactively choose a ruleset to view from only rulesets configured in the current repository $ gh ruleset view --no-parents # View a ruleset configured in the current repository or any of its parents $ gh ruleset view 43 # View a ruleset configured in a different repository or any of its parents $ gh ruleset view 23 --repo owner/repo # View an organization-level ruleset $ gh ruleset view 23 --org my-org Clones labels from a source repository to a destination repository on GitHub. By default, the destination repository is the current repository. All labels from the source repository will be copied to the destination repository. Labels in the destination repository that are not in the source repository will not be deleted or modified. Labels from the source repository that already exist in the destination repository will be skipped. You can overwrite existing labels in the destination repository using the %[1]s--force%[1]s flag. List issues in a GitHub repository. By default, this only lists open issues. The search query syntax is documented here: On supported GitHub hosts, advanced issue search syntax can be used in the %[1]s--search%[1]s query. For more information about advanced issue search, see: query PullRequestList( $owner: String!, $repo: String!, $limit: Int!, $endCursor: String, $baseBranch: String, $headBranch: String, $state: [PullRequestState!] = OPEN ) { repository(owner: $owner, name: $repo) { pullRequests( states: $state, baseRefName: $baseBranch, headRefName: $headBranch, first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC} ) { totalCount nodes { ...pr } pageInfo { hasNextPage endCursor } } } } {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} {{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} {{- color "default+hb"}}{{ .Message }} {{color "reset"}} {{- if .Answer}} {{- color "cyan"}}{{.Answer}}{{color "reset"}}{{"\n"}} {{- else }} {{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}} {{- color "white"}}{{if .Default}}(Y/n) {{else}}(y/N) {{end}}{{color "reset"}} {{- end}} List pull requests in a GitHub repository. By default, this only lists open PRs. The search query syntax is documented here: On supported GitHub hosts, advanced issue search syntax can be used in the %[1]s--search%[1]s query. For more information about advanced issue search, see: # Open a browser to add write:org and read:public_key scopes $ gh auth refresh --scopes write:org,read:public_key # Open a browser to ensure your authentication credentials have the correct minimum scopes $ gh auth refresh # Open a browser to idempotently remove the delete_repo scope $ gh auth refresh --remove-scopes delete_repo # Open a browser to re-authenticate with the default minimum scopes $ gh auth refresh --reset-scopes # Open a browser to re-authenticate and copy one-time OAuth code to clipboard $ gh auth refresh --clipboard Sync destination repository from source repository. Syncing uses the default branch of the source repository to update the matching branch on the destination repository so they are equal. A fast forward update will be used except when the %[1]s--force%[1]s flag is specified, then the two branches will be synced using a hard reset. Without an argument, the local repository is selected as the destination repository. The source repository is the parent of the destination repository by default. This can be overridden with the %[1]s--source%[1]s flag. Set a value for a secret on one of the following levels: - repository (default): available to GitHub Actions runs or Dependabot in a repository - environment: available to GitHub Actions runs for a deployment environment in a repository - organization: available to GitHub Actions runs, Dependabot, or Codespaces within an organization - user: available to Codespaces for your user Organization and user secrets can optionally be restricted to only be available to specific repositories. Secret values are locally encrypted before being sent to GitHub. # List the first 30 extensions sorted by star count, descending $ gh ext search # List more extensions $ gh ext search --limit 300 # List extensions matching the term "branch" $ gh ext search branch # List extensions owned by organization "github" $ gh ext search --owner github # List extensions, sorting by recently updated, ascending $ gh ext search --sort updated --order asc # List extensions, filtering by license $ gh ext search --license MIT # Open search results in the browser $ gh ext search -w Generate the autocompletion script for the zsh shell. If shell completion is not already enabled in your environment you will need to enable it. You can execute the following once: echo "autoload -U compinit; compinit" >> ~/.zshrc To load completions in your current shell session: source <(%[1]s completion zsh) To load completions for every new session, execute once: #### Linux: %[1]s completion zsh > "${fpath[1]}/_%[1]s" #### macOS: %[1]s completion zsh > $(brew --prefix)/share/zsh/site-functions/_%[1]s You will need to start a new shell for this setup to take effect. # Search code matching "react" and "lifecycle" $ gh search code react lifecycle # Search code matching "error handling" $ gh search code "error handling" # Search code matching "deque" in Python files $ gh search code deque --language=python # Search code matching "cli" in repositories owned by microsoft organization $ gh search code cli --owner=microsoft # Search code matching "panic" in the GitHub CLI repository $ gh search code panic --repo cli/cli # Search code matching keyword "lint" in package.json files $ gh search code lint --filename package.json Edit repository settings. To toggle a setting off, use the %[1]s--=false%[1]s syntax. Changing repository visibility can have unexpected consequences including but not limited to: - Losing stars and watchers, affecting repository ranking - Detaching public forks from the network - Disabling push rulesets - Allowing access to GitHub Actions history and logs When the %[1]s--visibility%[1]s flag is used, %[1]s--accept-visibility-change-consequences%[1]s flag is required. For information on all the potential consequences, see . # Have gh prompt you for what workflow you'd like to run and interactively collect inputs $ gh workflow run # Run the workflow file 'triage.yml' at the remote's default branch $ gh workflow run triage.yml # Run the workflow file 'triage.yml' at a specified ref $ gh workflow run triage.yml --ref my-branch # Run the workflow file 'triage.yml' with command line inputs $ gh workflow run triage.yml -f name=scully -f greeting=hello # Run the workflow file 'triage.yml' with JSON via standard input $ echo '{"name":"scully", "greeting":"hello"}' | gh workflow run triage.yml --json statusCheckRollup: commits(last: 1) { nodes { commit { statusCheckRollup { contexts(first:100%[1]s) { nodes { __typename ...on StatusContext { context, state, targetUrl, createdAt, description, isRequired(pullRequestId: %[2]s) }, ...on CheckRun { name, checkSuite{workflowRun{%[3]sworkflow{name}}}, status, conclusion, startedAt, completedAt, detailsUrl, isRequired(pullRequestId: %[2]s) } }, pageInfo{hasNextPage,endCursor} } } } } } # Open the home page of the current repository $ gh browse # Open the script directory of the current repository $ gh browse script/ # Open issue or pull request 217 $ gh browse 217 # Open commit page $ gh browse 77507cd94ccafcf568f8560cfecde965fcfa63 # Open repository settings $ gh browse --settings # Open main.go at line 312 $ gh browse main.go:312 # Open main.go with the repository at head of bug-fix branch $ gh browse main.go --branch bug-fix # Open main.go with the repository at commit 775007cd $ gh browse main.go --commit=77507cd94ccafcf568f8560cfecde965fcfa63 Bash Session bash-session console shell-session *.sh-session text/x-sh true # Verify an artifact linked with a repository $ gh attestation verify example.bin --repo github/example # Verify an artifact linked with an organization $ gh attestation verify example.bin --owner github # Verify an artifact and output the full verification result $ gh attestation verify example.bin --owner github --format json # Verify an OCI image using attestations stored on disk $ gh attestation verify oci:// --owner github --bundle sha256:foo.jsonl # Verify an artifact signed with a reusable workflow $ gh attestation verify example.bin --owner github --signer-repo actions/example # Search commits matching set of keywords "readme" and "typo" $ gh search commits readme typo # Search commits matching phrase "bug fix" $ gh search commits "bug fix" # Search commits committed by user "monalisa" $ gh search commits --committer=monalisa # Search commits authored by users with name "Jane Doe" $ gh search commits --author-name="Jane Doe" # Search commits matching hash "8dd03144ffdc6c0d486d6b705f9c7fba871ee7c3" $ gh search commits --hash=8dd03144ffdc6c0d486d6b705f9c7fba871ee7c3 # Search commits authored before February 1st, 2022 $ gh search commits --author-date="<2022-02-01" Runs the GitHub Copilot CLI. Executing the Copilot CLI through %[1]sgh%[1]s is currently in preview and subject to change. If already installed, %[1]sgh%[1]s will execute the Copilot CLI found in your %[1]sPATH%[1]s. If the Copilot CLI is not installed, it will be downloaded to %[2]s. Use %[1]s--remove%[1]s to remove the downloaded Copilot CLI. This command is only supported on Windows, Linux, and Darwin, on amd64/x64 or arm64 architectures. To prevent %[1]sgh%[1]s from interpreting flags intended for Copilot, use %[1]s--%[1]s before Copilot flags and args. Learn more at https://gh.io/copilot-cli BNF bnf *.bnf text/x-bnf # List caches for current repository $ gh cache list # List caches for specific repository $ gh cache list --repo cli/cli # List caches sorted by least recently accessed $ gh cache list --sort last_accessed_at --order asc # List caches that have keys matching a prefix (or that match exactly) $ gh cache list --key key-prefix # List caches for a specific branch, replace with the actual branch name $ gh cache list --ref refs/heads/ # List caches for a specific pull request, replace with the actual pull request number $ gh cache list --ref refs/pull//merge {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} {{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} {{- color "default+hb"}}{{ .Message }} {{color "reset"}} {{- if .ShowAnswer}} {{- color "cyan"}}{{.Answer}}{{color "reset"}}{{"\n"}} {{- else }} {{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}} {{- if and .Default (not .HideDefault)}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}} {{- color "cyan"}}[Enter to launch editor] {{color "reset"}} {{- end}} # Note: Command Prompt on Windows requires using double quotes for arguments $ gh alias set pv 'pr view' $ gh pv -w 123 #=> gh pr view -w 123 $ gh alias set bugs 'issue list --label=bugs' $ gh bugs $ gh alias set homework 'issue list --assignee @me' $ gh homework $ gh alias set 'issue mine' 'issue list --mention @me' $ gh issue mine $ gh alias set epicsBy 'issue list --author="$1" --label="epic"' $ gh epicsBy vilmibm #=> gh issue list --author="vilmibm" --label="epic" $ gh alias set --shell igrep 'gh issue list --label="$1" | grep "$2"' $ gh igrep epic foo #=> gh issue list --label="epic" | grep "foo" View a summary of a workflow run. Due to platform limitations, %[1]sgh%[1]s may not always be able to associate jobs with their corresponding logs when using the primary method of fetching logs in zip format. In such cases, %[1]sgh%[1]s will attempt to fetch logs for each job individually via the API. This fallback is slower and more resource-intensive. If more than 25 job logs are missing, the operation will fail with an error. Additionally, due to similar platform constraints, some log lines may not be associated with a specific step within a job. In these cases, the step name will appear as %[1]sUNKNOWN STEP%[1]s in the log output. List gists from your user account. You can use a regular expression to filter the description, file names, or even the content of files in the gist using %[1]s--filter%[1]s. For supported regular expression syntax, see . Use %[1]s--include-content%[1]s to include content of files, noting that this will be slower and increase the rate limit used. Instead of printing a table, code will be printed with highlights similar to %[1]sgh search code%[1]s: {{gist ID}} {{file name}} {{description}} {{matching lines from content}} No highlights or other color is printed when output is redirected. MinTTY is the terminal emulator that comes by default with Git for Windows. It has known issues with gh's ability to prompt a user for input. There are a few workarounds to make gh work with MinTTY: - Reinstall Git for Windows, checking "Enable experimental support for pseudo consoles". - Use a different terminal emulator with Git for Windows like Windows Terminal. You can run %[1]sC:\Program Files\Git\bin\bash.exe%[1]s from any terminal emulator to continue using all of the tooling in Git For Windows without MinTTY. - Prefix invocations of gh with %[1]swinpty%[1]s, eg: %[1]swinpty gh auth login%[1]s. NOTE: this can lead to some UI bugs. # Search issues matching set of keywords "readme" and "typo" $ gh search issues readme typo # Search issues matching phrase "broken feature" $ gh search issues "broken feature" # Search issues and pull requests in cli organization $ gh search issues --include-prs --owner=cli # Search open issues assigned to yourself $ gh search issues --assignee=@me --state=open # Search issues with numerous comments $ gh search issues --comments=">100" # Search issues without label "bug" $ gh search issues -- -label:bug # Search issues only from un-archived repositories (default is all repositories) $ gh search issues --owner github --archived=false # Delete a cache by id $ gh cache delete 1234 # Delete a cache by key $ gh cache delete cache-key # Delete a cache by id in a specific repo $ gh cache delete 1234 --repo cli/cli # Delete a cache by key and branch ref $ gh cache delete cache-key --ref refs/heads/feature-branch # Delete a cache by key and PR ref $ gh cache delete cache-key --ref refs/pull//merge # Delete all caches (exit code 1 on no caches) $ gh cache delete --all # Delete all caches for a specific ref $ gh cache delete --all --ref refs/pull//merge # Delete all caches (exit code 0 on no caches) $ gh cache delete --all --succeed-on-no-caches Display active account and authentication state on each known GitHub host. For each host, the authentication state of each known account is tested and any issues are included in the output. Each host section will indicate the active account, which will be used when targeting that host. If an account on any host (or only the one given via %[1]s--hostname%[1]s) has authentication issues, the command will exit with 1 and output to stderr. Note that when using the %[1]s--json%[1]s option, the command will always exit with zero regardless of any authentication issues, unless there is a fatal error. To change the active account for a host, see %[1]sgh auth switch%[1]s. List GitHub rulesets for a repository or organization. If no options are provided, the current repository's rulesets are listed. You can query a different repository's rulesets by using the %[1]s--repo%[1]s flag. You can also use the %[1]s--org%[1]s flag to list rulesets configured for the provided organization. Use the %[1]s--parents%[1]s flag to control whether rulesets configured at higher levels that also apply to the provided repository or organization should be returned. The default is %[1]strue%[1]s. Your access token must have the %[1]sadmin:org%[1]s scope to use the %[1]s--org%[1]s flag, which can be granted by running %[1]sgh auth refresh -s admin:org%[1]s. Rerun an entire run, only failed jobs, or a specific job from a run. Note that due to historical reasons, the %[1]s--job%[1]s flag may not take what you expect. Specifically, when navigating to a job in the browser, the URL looks like this: %[1]shttps://github.com///actions/runs//jobs/%[1]s. However, this %[1]s%[1]s should not be used with the %[1]s--job%[1]s flag and will result in the API returning %[1]s404 NOT FOUND%[1]s. Instead, you can get the correct job IDs using the following command: gh run view --json jobs --jq '.jobs[] | {name, databaseId}' You will need to use databaseId field for triggering job re-runs. Import aliases from the contents of a YAML file. Aliases should be defined as a map in YAML, where the keys represent aliases and the values represent the corresponding expansions. An example file should look like the following: bugs: issue list --label=bug igrep: '!gh issue list --label="$1" | grep "$2"' features: |- issue list --label=enhancement Use %[1]s-%[1]s to read aliases (in YAML format) from standard input. The output from %[1]sgh alias list%[1]s can be used to produce a YAML file containing your aliases, which you can use to import them from one machine to another. Run %[1]sgh help alias list%[1]s to learn more. # Search pull requests matching set of keywords "fix" and "bug" $ gh search prs fix bug # Search draft pull requests in cli repository $ gh search prs --repo=cli/cli --draft # Search open pull requests requesting your review $ gh search prs --review-requested=@me --state=open # Search merged pull requests assigned to yourself $ gh search prs --assignee=@me --merged # Search pull requests with numerous reactions $ gh search prs --reactions=">100" # Search pull requests without label "bug" $ gh search prs -- -label:bug # Search pull requests only from un-archived repositories (default is all repositories) $ gh search prs --owner github --archived=false {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} {{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} {{- color "default+hb"}}{{ .Message }} {{color "reset"}} {{- if .ShowAnswer}} {{- color "cyan"}}{{.Answer}}{{color "reset"}}{{"\n"}} {{- else }} {{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}} {{- if and .Default (not .HideDefault)}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}} {{- color "cyan"}}[(e) to launch {{ .EditorCommand }}{{- if .BlankAllowed }}, enter to skip{{ end }}] {{color "reset"}} {{- end}} This command will take over your terminal and run a fully interactive interface for browsing, adding, and removing gh extensions. A terminal width greater than 100 columns is recommended. To learn how to control this interface, press %[1]s?%[1]s after running to see the help text. Press %[1]sq%[1]s to quit. Running this command with %[1]s--single-column%[1]s should make this command more intelligible for users who rely on assistive technology like screen readers or high zoom. For a more traditional way to discover extensions, see: gh ext search along with %[1]sgh ext install%[1]s, %[1]sgh ext remove%[1]s, and %[1]sgh repo view%[1]s. query IssueStatus($owner: String!, $repo: String!, $viewer: String!, $per_page: Int = 10) { repository(owner: $owner, name: $repo) { hasIssuesEnabled assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) { totalCount nodes { ...issue } } mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) { totalCount nodes { ...issue } } authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: UPDATED_AT, direction: DESC}) { totalCount nodes { ...issue } } } } # Select a gist to edit interactively $ gh gist edit # Edit a gist file in the default editor $ gh gist edit 1234567890abcdef1234567890abcdef # Edit a specific file in the gist $ gh gist edit 1234567890abcdef1234567890abcdef --filename hello.py # Replace a gist file with content from a local file $ gh gist edit 1234567890abcdef1234567890abcdef --filename hello.py hello.py # Add a new file to the gist $ gh gist edit 1234567890abcdef1234567890abcdef --add newfile.py # Change the description of the gist $ gh gist edit 1234567890abcdef1234567890abcdef --desc "new description" # Remove a file from the gist $ gh gist edit 1234567890abcdef1234567890abcdef --remove hello.py # Search repositories matching set of keywords "cli" and "shell" $ gh search repos cli shell # Search repositories matching phrase "vim plugin" $ gh search repos "vim plugin" # Search repositories public repos in the microsoft organization $ gh search repos --owner=microsoft --visibility=public # Search repositories with a set of topics $ gh search repos --topic=unix,terminal # Search repositories by coding language and number of good first issues $ gh search repos --language=go --good-first-issues=">=10" # Search repositories without topic "linux" $ gh search repos -- -topic:linux # Search repositories excluding archived repositories $ gh search repos --archived=false