Pular para o conteúdo principal

CLI

Installing gh on Windows

WinGet

The GitHub CLI package is supported by Microsoft with updates powered by microsoft/winget-pkgs.

  • To install:
winget install --id GitHub.cli
  • To upgrade:
winget upgrade --id GitHub.cli
  • Verify installation:
gh --version
observação

The Windows installer modifies your PATH. When using Windows Terminal, you will need to open a new window for the changes to take effect. (Simply opening a new tab will not be sufficient.)

Precompiled binaries

GitHub CLI releases contain precompiled exe and msi binaries for 386, amd64 and arm64 architectures.

GitHub CLI manual

Display or change configuration settings

gh config --help
Display or change configuration settings for gh.

Current respected settings:
- `git_protocol`: the protocol to use for git clone and push operations `{https | ssh}` (default `https`)
- `editor`: the text editor program to use for authoring text
- `prompt`: toggle interactive prompting in the terminal `{enabled | disabled}` (default `enabled`)
- `prefer_editor_prompt`: toggle preference for editor-based interactive prompting in the terminal `{enabled | disabled}` (default `disabled`)
- `pager`: the terminal pager program to send standard output to
- `http_unix_socket`: the path to a Unix socket through which to make an HTTP connection
- `browser`: the web browser to use for opening URLs
- `color_labels`: whether to display labels using their RGB hex color codes in terminals that support truecolor `{enabled | disabled}` (default `disabled`)
- `accessible_colors`: whether customizable, 4-bit accessible colors should be used `{enabled | disabled}` (default `disabled`)
- `accessible_prompter`: whether an accessible prompter should be used `{enabled | disabled}` (default `disabled`)
- `spinner`: whether to use a animated spinner as a progress indicator `{enabled | disabled}` (default `enabled`)

USAGE
gh config <command> [flags]

AVAILABLE COMMANDS
clear-cache: Clear the cli cache
get: Print the value of a given configuration key
list: Print a list of configuration keys and values
set: Update configuration with a value for the given key

INHERITED FLAGS
--help Show help for command

LEARN MORE
Use `gh <command> <subcommand> --help` for more information about a command.
Read the manual at https://cli.github.com/manual
Learn about exit codes using `gh help exit-codes`
Learn about accessibility experiences using `gh help accessibility`
gh config set editor "code --wait"
gh config set browser ""
gh config get browser

Authenticate gh and git with GitHub

gh auth --help
Authenticate gh and git with GitHub

USAGE
gh auth <command> [flags]

AVAILABLE COMMANDS
login: Log in to a GitHub account
logout: Log out of a GitHub account
refresh: Refresh stored authentication credentials
setup-git: Setup git with GitHub CLI
status: Display active account and authentication state on each known GitHub host
switch: Switch active GitHub account
token: Print the authentication token gh uses for a hostname and account

Log in to a GitHub account

gh auth login

Log out of a GitHub account

gh auth logout

Display active account and authentication state on each known GitHub host

gh auth status

Work with GitHub organizations.

List organizations for the authenticated user.

gh org list
Work with GitHub organizations.

USAGE
gh org <command> [flags]

GENERAL COMMANDS
list: List organizations for the authenticated user.

INHERITED FLAGS
--help Show help for command

EXAMPLES
$ gh org list

Work with GitHub repositories.

gh repo create --help
Usage:  gh repo create [<name>] [flags]

Flags:
--add-readme Add a README file to the new repository
-c, --clone Clone the new repository to the current directory
-d, --description string Description of the repository
--disable-issues Disable issues in the new repository
--disable-wiki Disable wiki in the new repository
-g, --gitignore string Specify a gitignore template for the repository
-h, --homepage URL Repository home page URL
--include-all-branches Include all branches from template repository
--internal Make the new repository internal
-l, --license string Specify an Open Source License for the repository
--private Make the new repository private
--public Make the new repository public
--push Push local commits to the new repository
-r, --remote string Specify remote name for the new repository
-s, --source string Specify path to local repository to use as source
-t, --team name The name of the organization team to be granted access
-p, --template repository Make the new repository based on a template repository
EXAMPLES
# Create a repository interactively
$ gh repo create

# Create a new remote repository and clone it locally
$ gh repo create my-project --public --clone

# Create a new remote repository in a different organization
$ gh repo create my-org/my-project --public

# Create a remote repository from the current directory
$ gh repo create my-project --private --source=. --remote=upstream
gh repo create ELT73A-S22-2025-2-X/LAB00 --public -c -l mit --add-readme -g C
gh repo view ELT73A-S22-2025-2-X/LAB00 --web
gh repo delete ELT73A-S22-2025-2-X/LAB00x --yes
gh repo create ELT73A-S22-2025-2-X/LAB00c --public -c -l mit --add-readme -g C
gh repo view ELT73A-S22-2025-2-X/LAB00c --web
gh repo create ELT73A-S22-2025-2-X/LAB00 --public --template ELT73A-LAB-TPL/LAB00

Cria repo de template, clona e abre no VScode

gh repo create ELT73A-S22-2025-2-X/LAB00h --public -p ELT73A-LAB-TPL/LAB00 -c
cd LAB00y
code .

Crie um novo repositório com base em um template:

gh repo create ELT73A-S22-2025-2-X/LAB00-tmp --public --template ELT73A-LAB-TPL/LAB00
gh repo create ELT73A-S22-2025-2-X/LAB00-tmp --private --template ELT73A-LAB-TPL/LAB00

gh repo clone ELT73A-2025-1-X/my-new-repo

gh repo delete ELT73A-S22-2025-2-X/LAB00x --yes

Abra o repositório no Navegador Web:

gh repo view ELT73A-LAB-TPL/LAB00 --web
gh repo create ELT73A-S22-2025-2-X/LAB00x
gh repo list ELT73A-S22-2025-2-X
gh auth refresh -h github.com -s delete_repo

License

For more information, see: http://choosealicense.com/licenses/

gh repo license list
LICENSE KEYSPDX IDLICENSE NAME
agpl-3.0AGPL-3.0GNU Affero General Public License v3.0
apache-2.0Apache-2.0Apache License 2.0
bsd-2-clauseBSD-2-ClauseBSD 2-Clause "Simplified" License
bsd-3-clauseBSD-3-ClauseBSD 3-Clause "New" or "Revised" License
bsl-1.0BSL-1.0Boost Software License 1.0
cc0-1.0CC0-1.0Creative Commons Zero v1.0 Universal
epl-2.0EPL-2.0Eclipse Public License 2.0
gpl-2.0GPL-2.0GNU General Public License v2.0
gpl-3.0GPL-3.0GNU General Public License v3.0
lgpl-2.1LGPL-2.1GNU Lesser General Public License v2.1
mitMITMIT License
mpl-2.0MPL-2.0Mozilla Public License 2.0
unlicenseUnlicenseThe Unlicense
gh repo license --help
View a specific repository license by license key or SPDX ID.

Run `gh repo license list` to see available commonly used licenses.
For even more licenses, visit <https://choosealicense.com/appendix>.

USAGE
gh repo license view {<license-key> | <spdx-id>} [flags]

FLAGS
-w, --web Open https://choosealicense.com/ in the browser

INHERITED FLAGS
--help Show help for command

EXAMPLES
# View the MIT license from SPDX ID
$ gh repo license view MIT

# View the MIT license from license key
$ gh repo license view mit

# View the GNU AGPL-3.0 license from SPDX ID
$ gh repo license view AGPL-3.0

# View the GNU AGPL-3.0 license from license key
$ gh repo license view agpl-3.0

# Create a LICENSE.md with the MIT license
$ gh repo license view MIT > LICENSE.md

Releases

Manage releases

gh release create [<tag>] [<filename>... | <pattern>...]

gh release create --help

Create a new GitHub Release for a repository.

A list of asset files may be given to upload to the new release. To define a display label for an asset, append text starting with # after the file name.

If a matching git tag does not yet exist, one will automatically get created from the latest state of the default branch. Use --target to point to a different branch or commit for the automatic tag creation. Use --verify-tag to abort the release if the tag doesn't already exist. To fetch the new tag locally after the release, do git fetch --tags origin.

To create a release from an annotated git tag, first create one locally with git, push the tag to GitHub, then run this command. Use --notes-from-tag to get the release notes from the annotated git tag. If the tag is not annotated, the commit message will be used instead.

Use --generate-notes to automatically generate notes using GitHub Release Notes API. When using automatically generated release notes, a release title will also be automatically generated unless a title was explicitly passed. Additional release notes can be prepended to automatically generated notes by using the --notes flag.

By default, the release is created even if there are no new commits since the last release. This may result in the same or duplicate release which may not be desirable in some cases. Use --fail-on-no-commits to fail if no new commits are available. This flag has no effect if there are no existing releases or this is the very first release.

USAGE
gh release create [<tag>] [<filename>... | <pattern>...]

ALIASES
gh release new

FLAGS
--discussion-category string Start a discussion in the specified category
-d, --draft Save the release as a draft instead of publishing it
--fail-on-no-commits Fail if there are no commits since the last release (no impact on the first release)
--generate-notes Automatically generate title and notes for the release via GitHub Release Notes API
--latest Mark this release as "Latest" (default [automatic based on date and version]). --latest=false to explicitly NOT set as latest
-n, --notes string Release notes
-F, --notes-file file Read release notes from file (use "-" to read from standard input)
--notes-from-tag Fetch notes from the tag annotation or message of commit associated with tag
--notes-start-tag string Tag to use as the starting point for generating release notes
-p, --prerelease Mark the release as a prerelease
--target branch Target branch or full commit SHA (default [main branch])
-t, --title string Release title
--verify-tag Abort in case the git tag doesn't already exist in the remote repository

INHERITED FLAGS
--help Show help for command
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format

EXAMPLES

  # Interactively create a release
$ gh release create

# Interactively create a release from specific tag
$ gh release create v1.2.3

# Non-interactively create a release
$ gh release create v1.2.3 --notes "bugfix release"

# Use automatically generated via GitHub Release Notes API release notes
$ gh release create v1.2.3 --generate-notes

# Use release notes from a file
$ gh release create v1.2.3 -F release-notes.md

# Use tag annotation or associated commit message as notes
$ gh release create v1.2.3 --notes-from-tag

# Don't mark the release as latest
$ gh release create v1.2.3 --latest=false

# Upload all tarballs in a directory as release assets
$ gh release create v1.2.3 ./dist/*.tgz

# Upload a release asset with a display label
$ gh release create v1.2.3 '/path/to/asset.zip#My display label'

# Create a release and start a discussion
$ gh release create v1.2.3 --discussion-category "General"

# Create a release only if there are new commits available since the last release
$ gh release create v1.2.3 --fail-on-no-commits

LEARN MORE

  • Use gh <command> <subcommand> --help for more information about a command.
  • Read the manual at https://cli.github.com/manual
  • Learn about exit codes using gh help exit-codes
  • Learn about accessibility experiences using gh help accessibility