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
Print active auth token
gh auth token

# Print the active token for scripting.

Switch active account
gh auth switch

# Switch between authenticated accounts on a host.

Configure Git protocol auth
gh auth setup-git

# Configure Git to use GitHub CLI as a credential helper.

Set git protocol to ssh
gh config set git_protocol ssh

# Set the preferred Git protocol used by gh.

Authenticate with token from stdin
printenv GITHUB_TOKEN | gh auth login --with-token

# Authenticate non-interactively using a token piped from stdin.

Use GH_ENTERPRISE_TOKEN env var
export GH_HOST=github.example.com && export GH_ENTERPRISE_TOKEN=token

# Authenticate automation against GitHub Enterprise Server using env vars.

Set default host env var
export GH_HOST=github.example.com

# Set the default host for gh commands.

Set GH_REPO for scripts
export GH_REPO=my-org/platform-api

# Set the default repository context for scripts.

## Aliases, Extensions, and Completion
List aliases
gh alias list

# List configured aliases.

Create an alias
gh alias set pv "pr view"

# Create a simple alias.

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

# Create a shell-powered alias.

Delete an alias
gh alias delete pv

# Delete a configured alias.

Import aliases from YAML
gh alias import aliases.yml --clobber

# Import aliases from a YAML file.

List installed extensions
gh extension list

# List installed gh extensions.

Install an extension
gh extension install dlvhdr/gh-dash

# Install a GitHub CLI extension from a repo.

Upgrade extensions
gh extension upgrade --all

# Upgrade installed extensions.

Remove an extension
gh extension remove dlvhdr/gh-dash

# Uninstall an extension.

Generate Bash completions
gh completion -s bash > /etc/bash_completion.d/gh

# Generate shell completion for Bash.

Generate Zsh completions
gh completion -s zsh > "${fpath[1]}/_gh"

# Generate shell completion for Zsh.

Generate Fish completions
gh completion -s fish > ~/.config/fish/completions/gh.fish

# Generate shell completion for Fish.

## Organizations, Projects, and Admin Utilities
List organizations for account
gh org list

# List organizations visible to your account.

List projects
gh project list --owner @me

# List GitHub Projects for an owner.

View a project
gh project view 5 --owner my-org

# Show a GitHub Project.

List org secrets
gh secret list --org my-org

# List organization secrets.

Set org secret
gh secret set MY_TOKEN --org my-org --visibility all < token.txt

# Create an organization secret.

List org variables
gh variable list --org my-org

# List organization variables.

Set org variable
gh variable set APP_REGION --org my-org --body us-west-2

# Create or update an organization variable.

Add an SSH key
gh ssh-key add ~/.ssh/id_ed25519.pub --title "work-laptop"

# Upload an SSH public key.

Add a GPG key
gh gpg-key add ~/.gnupg/public.asc

# Upload a GPG key.

List common licenses
gh license list

# List common software licenses.

View a license template
gh license view mit

# Show a license template body.

Recommended next

No recommendations yet.