gh-variable
Manage GitHub repository variables
TLDR
List variables for the current repository
List variables for a specific organization
Get a variable for the current repository
Set a variable for the current repository (user will be prompted for the value)
Set a variable for a deployment environment in the current repository
Set an organization variable visible to all repositories
Set multiple variables from a dotenv file
Delete a variable for the current repository
SYNOPSIS
gh variable <list|set|delete> [NAME] [VALUE] [<flags>]
PARAMETERS
--env <string>
Target environment name (production, staging, development)
--org <string>
Operate on organization variables
--repo [<OWNER/>]<NAME>
Operate on specific repository
--limit <int>
Maximum variables to list (default 30, for list)
--show-vals
Display variable values (for list)
--json [<fields>]
Output as JSON (for list)
--body-path <file>
Read variable value from file (for set)
DESCRIPTION
gh variable is a subcommand of the GitHub CLI (gh) for managing environment variables in GitHub repositories, organizations, and environments. It enables listing, creating, updating, and deleting variables used in GitHub Actions workflows via command line, avoiding the web UI.
Variables store non-sensitive data like API keys or config values, visible to repository collaborators (unlike encrypted secrets). Target specific contexts with --repo, --org, or --env (e.g., production, staging). List variables with optional JSON output or value display; set from direct input, stdin, or files; delete precisely.
Ideal for CI/CD automation, scripting deployments, and team workflows. Requires authentication via gh auth login. Supports pagination for large sets.
CAVEATS
Requires GitHub CLI installed and user authenticated. Variables are unencrypted and visible to repo/org collaborators. No bulk operations; use scripts for multiples. Environment support limited to named ones.
EXAMPLES
Set variable: gh variable set MY_API_KEY "value" --repo owner/repo --env production
List: gh variable list --repo owner/repo --show-vals
Delete: gh variable delete MY_VAR --org myorg
VALUE INPUT
For set, omit VALUE to read from stdin: echo "secret" | gh variable set KEY --body-path - or use file with --body-path file.txt.
HISTORY
Part of GitHub CLI v1.0.0 (Dec 2020). Environment targeting added in v2.0+ (2022). JSON output and limits improved in recent updates for better scripting.


