The gh config Command

GitHub CLI configuration works similarly to git config — you can get, set, and list settings.

Setting Values

gh config set <key> <value>
 
# Examples
gh config set editor vim
gh config set pager "less -R"
gh config set git_protocol ssh
gh config set browser "firefox"
gh config set prompt disabled       # Disable interactive prompts

Getting Values

gh config get <key>
 
# Examples
gh config get editor
gh config get git_protocol

Listing All Settings

gh config list

Clearing the Cache

gh config clear-cache

Configuration Keys

KeyValuesDefaultDescription
git_protocolhttps, sshhttpsDefault protocol for Git operations
editorAny editor command$GH_EDITOR, $VISUAL, or $EDITOREditor for composing text (issues, PRs)
promptenabled, disabledenabledWhether to use interactive prompts
pagerAny pager command$GH_PAGER, $PAGER, or lessPager for long output
http_unix_socketSocket pathUnix socket for HTTP connections
browserAny browser command$GH_BROWSER or $BROWSERWeb browser for --web commands

Host-Specific Configuration

Settings can be scoped to a specific host:

# Set SSH only for github.com, keep HTTPS for enterprise
gh config set git_protocol ssh --host github.com
gh config set git_protocol https --host github.example.com

Configuration Files

All files live in ~/.config/gh/ (override with $GH_CONFIG_DIR).

config.yml

Global settings and aliases:

git_protocol: ssh
editor: vim
prompt: enabled
pager: less
aliases:
  co: pr checkout
  pvw: pr view --web

hosts.yml

Per-host authentication and settings:

github.com:
  user: yourname
  oauth_token: gho_xxxxxxxxxxxx
  git_protocol: ssh

You can edit these files directly or use gh config set.

Environment Variables

Environment variables override config file settings. They are especially useful in CI/CD and scripts.

Authentication

VariablePurpose
GH_TOKEN / GITHUB_TOKENAuth token for github.com and *.ghe.com
GH_ENTERPRISE_TOKEN / GITHUB_ENTERPRISE_TOKENAuth token for GitHub Enterprise Server

Host & Repository

VariablePurpose
GH_HOSTDefault GitHub hostname when not specified
GH_REPODefault repository in [HOST/]OWNER/REPO format

Editors & Browsers

VariablePurpose
GH_EDITOREditor for composing text (highest priority)
GIT_EDITORFallback editor
VISUALFallback editor
EDITORFallback editor (lowest priority)
GH_BROWSER / BROWSERWeb browser for --web commands

Output & Display

VariablePurpose
GH_PAGER / PAGERTerminal pager (e.g., less, bat)
GH_FORCE_TTYForce terminal-style output when piping
GH_MDWIDTHMax width for markdown rendering
NO_COLORSet to any value to disable ANSI colors
CLICOLORSet to 0 to disable colors
CLICOLOR_FORCESet to non-zero to keep colors when piping
GH_COLOR_LABELSDisplay labels with RGB hex colors
GLAMOUR_STYLEMarkdown rendering style (dark, light, notty)

Debugging

VariablePurpose
GH_DEBUGSet to 1 for verbose output; set to api for HTTP traffic

Miscellaneous

VariablePurpose
GH_CONFIG_DIROverride the config directory location
GH_PROMPT_DISABLEDDisable all interactive prompts
GH_NO_UPDATE_NOTIFIERSuppress update-available notices
GH_NO_EXTENSION_UPDATE_NOTIFIERSuppress extension update notices
GH_SPINNER_DISABLEDReplace spinner with text progress

Example: CI/CD Environment

export GH_TOKEN="ghp_xxxxxxxxxxxx"
export GH_REPO="myorg/myrepo"
export GH_PROMPT_DISABLED=1
export NO_COLOR=1
 
gh pr create --title "Automated PR" --body "Created by CI"

Exercises

  1. Run gh config list and review your current settings
  2. Set your preferred editor: gh config set editor "code --wait"
  3. Switch the default git protocol: gh config set git_protocol ssh
  4. Open ~/.config/gh/config.yml and inspect the file structure
  5. Try setting GH_DEBUG=1 and run any command to see verbose output