GH-VARIABLE-SET(1)

πŸ’… NAME πŸ’…

gh-variable-set β€” create or update variables, bestie. That's it. That's the whole gig. ✨

So this is the GitHub CLI manual's page for it, and tbh it's a little icon and you're gonna love her.


✨ SYNOPSIS ✨

gh variable set <variable-name> [flags]

πŸŽ€ DESCRIPTION πŸŽ€

Okay so here's the tea: gh variable set sets a value for a variable, and you get to pick which level it lives at. Three options, all valid, all iconic in their own way:

  • repository (this is the default, no cap): available to GitHub Actions runs or Dependabot in a repository
  • environment: available to GitHub Actions runs for a deployment environment in a repository
  • organization: available to GitHub Actions runs or Dependabot within an organization

And here's the extra little slay β€” an organization variable can optionally be restricted so it's only available to specific repositories. Not all of them. Just the chosen ones. πŸ‘‘


🌸 OPTIONS 🌸

  • -b, --body <string> β€” the value for the variable. And if you don't specify it? It literally reads from standard input. So you can pipe it in, feed it a file, whatever. 🫢
  • -e, --env <environment> β€” set deployment environment variable. That's the vibe.
  • -f, --env-file <file> β€” load variable names and values from a dotenv-formatted file. Bulk queen behavior.
  • -o, --org <organization> β€” set organization variable.
  • -r, --repos <repositories> β€” list of repositories that can access an organization variable. Gatekeeping, but make it deliberate. πŸ’…
  • -v, --visibility <string> (default "private") β€” set visibility for an organization variable: {all|private|selected}

πŸ¦‹ OPTIONS INHERITED FROM PARENT COMMANDS πŸ¦‹

  • -R, --repo <[HOST/]OWNER/REPO> β€” select another repository using the [HOST/]OWNER/REPO format. Passing the repo baton, iykyk.

🌈 EXIT CODES 🌈

  • 0: Successful execution πŸŽ‰
  • 1: Error 😭
  • 2: Command canceled
  • 4: Authentication required
NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information. Don't come for me, that's just what it says. πŸ’€

⭐ EXAMPLE ⭐

Honestly the examples are the main character here. Look at her go:

# Add variable value for the current repository in an interactive prompt
$ gh variable set MYVARIABLE

# Read variable value from an environment variable
$ gh variable set MYVARIABLE --body "$ENV_VALUE"

# Read variable value from a file
$ gh variable set MYVARIABLE < myfile.txt

# Set variable for a deployment environment in the current repository
$ gh variable set MYVARIABLE --env myenvironment

# Set organization-level variable visible to both public and private repositories
$ gh variable set MYVARIABLE --org myOrg --visibility all

# Set organization-level variable visible to specific repositories
$ gh variable set MYVARIABLE --org myOrg --repos repo1,repo2,repo3

# Set multiple variables imported from the ".env" file
$ gh variable set -f .env

The -f .env one? Multiple variables, one command. Ate. πŸ”₯


🧚 SEE ALSO 🧚

  • gh-variable(1) β€” go read her too, she's the parent and she's lovely.

Okay that's the whole page, bestie β€” no gatekeeping, every flag accounted for. This was GitHub CLI v2.102.0, dated Oct 2026, and it's giving documentation that actually respects your time. Mwah. πŸ’–πŸŽ€

πŸ“¦ where this page comes from