GitHub CLI Auth, Alias, and Config

Authentication, enterprise usage, aliases, extensions, completion, org secrets, and administrative helpers.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Auth, Tokens, and Enterprise

Credential flows, env vars, and multi-host usage.

Print active auth token

Print the active token for scripting.

bashANYauthtoken
bash
gh auth token
Notes

Print the active token for scripting.

Switch active account

Switch between authenticated accounts on a host.

bashANYauthaccount
bash
gh auth switch
Notes

Switch between authenticated accounts on a host.

Configure Git protocol auth

Configure Git to use GitHub CLI as a credential helper.

bashANYauthgit
bash
gh auth setup-git
Notes

Configure Git to use GitHub CLI as a credential helper.

Set git protocol to ssh

Set the preferred Git protocol used by gh.

bashANYconfiggitssh
bash
gh config set git_protocol ssh
Notes

Set the preferred Git protocol used by gh.

Authenticate with token from stdin

Authenticate non-interactively using a token piped from stdin.

bashANYauthtoken
bash
printenv GITHUB_TOKEN | gh auth login --with-token
Notes

Authenticate non-interactively using a token piped from stdin.

Use GH_ENTERPRISE_TOKEN env var

Authenticate automation against GitHub Enterprise Server using env vars.

bashANYenterpriseauthenv
bash
export GH_HOST=github.example.com && export GH_ENTERPRISE_TOKEN=token
Notes

Authenticate automation against GitHub Enterprise Server using env vars.

Set default host env var

Set the default host for gh commands.

bashANYenterprisehostenv
bash
export GH_HOST=github.example.com
Notes

Set the default host for gh commands.

Set GH_REPO for scripts

Set the default repository context for scripts.

bashANYenvrepoautomation
bash
export GH_REPO=my-org/platform-api
Notes

Set the default repository context for scripts.

Aliases, Extensions, and Completion

Customize gh for faster workflows.

List aliases

List configured aliases.

bashANYalias
bash
gh alias list
Notes

List configured aliases.

Create an alias

Create a simple alias.

bashANYaliasproductivity
bash
gh alias set pv "pr view"
Notes

Create a simple alias.

Create a shell alias

Create a shell-powered alias.

bashANYaliasshell
bash
gh alias set cleanup '!git branch --merged | egrep -v "(^\*|main|master)" | xargs -r git branch -d'
Notes

Create a shell-powered alias.

Delete an alias

Delete a configured alias.

bashANYalias
bash
gh alias delete pv
Notes

Delete a configured alias.

Import aliases from YAML

Import aliases from a YAML file.

bashANYaliasimport
bash
gh alias import aliases.yml --clobber
Notes

Import aliases from a YAML file.

List installed extensions

List installed gh extensions.

bashANYextension
bash
gh extension list
Notes

List installed gh extensions.

Install an extension

Install a GitHub CLI extension from a repo.

bashANYextensioninstall
bash
gh extension install dlvhdr/gh-dash
Notes

Install a GitHub CLI extension from a repo.

Upgrade extensions

Upgrade installed extensions.

bashANYextensionupgrade
bash
gh extension upgrade --all
Notes

Upgrade installed extensions.

Remove an extension

Uninstall an extension.

bashANYextensionremove
bash
gh extension remove dlvhdr/gh-dash
Notes

Uninstall an extension.

Generate Bash completions

Generate shell completion for Bash.

bashANYcompletionbash
bash
gh completion -s bash > /etc/bash_completion.d/gh
Notes

Generate shell completion for Bash.

Generate Zsh completions

Generate shell completion for Zsh.

bashANYcompletionzsh
bash
gh completion -s zsh > "${fpath[1]}/_gh"
Notes

Generate shell completion for Zsh.

Generate Fish completions

Generate shell completion for Fish.

bashANYcompletionfish
bash
gh completion -s fish > ~/.config/fish/completions/gh.fish
Notes

Generate shell completion for Fish.

Organizations, Projects, and Admin Utilities

Useful org-level and admin-oriented commands.

List organizations for account

List organizations visible to your account.

bashANYorg
bash
gh org list
Notes

List organizations visible to your account.

List projects

List GitHub Projects for an owner.

bashANYproject
bash
gh project list --owner @me
Notes

List GitHub Projects for an owner.

View a project

Show a GitHub Project.

bashANYproject
bash
gh project view 5 --owner my-org
Notes

Show a GitHub Project.

List org secrets

List organization secrets.

bashANYsecretorg
bash
gh secret list --org my-org
Notes

List organization secrets.

Set org secret

Create an organization secret.

bashANYsecretorg
bash
gh secret set MY_TOKEN --org my-org --visibility all < token.txt
Notes

Create an organization secret.

List org variables

List organization variables.

bashANYvariableorg
bash
gh variable list --org my-org
Notes

List organization variables.

Set org variable

Create or update an organization variable.

bashANYvariableorg
bash
gh variable set APP_REGION --org my-org --body us-west-2
Notes

Create or update an organization variable.

Add an SSH key

Upload an SSH public key.

bashANYssh-key
bash
gh ssh-key add ~/.ssh/id_ed25519.pub --title "work-laptop"
Notes

Upload an SSH public key.

Add a GPG key

Upload a GPG key.

bashANYgpg-key
bash
gh gpg-key add ~/.gnupg/public.asc
Notes

Upload a GPG key.

List common licenses

List common software licenses.

bashANYlicense
bash
gh license list
Notes

List common software licenses.

View a license template

Show a license template body.

bashANYlicense
bash
gh license view mit
Notes

Show a license template body.

Recommended next

No recommendations yet.