Home / Alt manpages / gh-variable-delete(1)

  • gh-variable-delete(1)
  • User command
  • linux

Delete a GitHub Actions Variable Safely with gh

This guide removes one GitHub Actions variable with the GitHub CLI, while making the target scope explicit first. It covers repository, deployment-environment and organisation variables, plus selecting a repository other than the current one.

Allow about five minutes for a single deletion, including a read-back check. You need GitHub CLI 2.87.3 or a compatible release, an authenticated account with access to the target, and the variable name. No root access or other elevated privilege is needed.

1. Check the command and choose a target

The installed command is from gh 2.87.3, released on 23 February 2026. Its default target is a repository variable. The same command can target a deployment environment with --env, or an organisation with --org. These are different variable records, even when they have the same name.

gh --version
gh variable delete --help

Look for the usage line and the three scope descriptions. The help also shows gh variable remove as an alias in this installed build. The local manpage documents the delete command and flags, but not that alias, so prefer delete in scripts and runbooks.

Checkpoint

Write down the variable name, repository, and scope before proceeding. If the scope is not clear, stop here and inspect the variable lists instead of guessing.

2. Inspect the existing variable

Read the record at the same scope that you intend to delete. The repository form uses the current repository context. Add --repo OWNER/REPO when working on a named repository, and use the same selector in later commands.

# Current repository
gh variable get EXAMPLE_VARIABLE

# A named repository
gh variable get EXAMPLE_VARIABLE --repo OWNER/REPO

# An environment variable
gh variable get EXAMPLE_VARIABLE --env production --repo OWNER/REPO

# An organisation variable
gh variable get EXAMPLE_VARIABLE --org EXAMPLE_ORG

Replace every capitalised placeholder. The get command prints the variable record, including its value in the ordinary form. Treat that output as sensitive if the value contains internal configuration. Do not paste it into a ticket or shell history unnecessarily.

For a machine-readable recovery note, you can request only the value. This deliberately prints the value to your terminal, so use it only where that is acceptable:

gh variable get EXAMPLE_VARIABLE   --repo OWNER/REPO   --json value   --jq .value

For an environment or organisation variable, add the corresponding --env or --org flag to both the inspection and deletion commands. Never omit it because the default is repository scope.

3. Warn before deleting

Deletion changes the GitHub configuration immediately. Workflows or Dependabot configuration that reads the variable may receive an empty value or behave differently afterwards. This is not a local file operation, and there is no --yes or confirmation flag in gh variable delete.

Save the value somewhere approved if you may need to recreate it. If the value is sensitive, use your organisation's secret-handling process rather than a plain text file. A variable is not the same thing as a GitHub Actions secret, so do not silently move the value to a different storage type as an attempted undo.

Check the scope one final time. A command with --org deletes the named organisation variable, not a repository variable of the same name. A command with --env deletes the variable for that deployment environment in the selected repository.

4. Delete the repository variable

For a variable in the current repository, run:

gh variable delete EXAMPLE_VARIABLE

For another repository, make the repository explicit:

gh variable delete EXAMPLE_VARIABLE --repo OWNER/REPO

A successful command exits with status zero. It may not need to print a success message, so check the status in automation rather than matching terminal text:

if gh variable delete EXAMPLE_VARIABLE --repo OWNER/REPO; then
  printf '%s
' 'Variable deleted'
else
  printf '%s
' 'Variable was not deleted' >&2
  exit 1
fi

Checkpoint

If this fails, do not retry with a different scope immediately. Check the variable name, repository, authentication host and permissions, then inspect the error.

5. Delete an environment or organisation variable

Use exactly one scope flag for the record you inspected:

# Deployment environment in a repository
gh variable delete EXAMPLE_VARIABLE   --env production   --repo OWNER/REPO

# Organisation-wide variable
gh variable delete EXAMPLE_VARIABLE   --org EXAMPLE_ORG

Environment variables belong to a repository and environment pair, so keep --repo beside --env when the target is not the current repository. Organisation variables are selected by organisation name. The command does not offer a flag to delete several variables at once; repeat the reviewed, scoped operation for each name.

6. Verify the deletion

Run the matching get command again. The command should no longer return the deleted variable as a normal record. Use the same scope and repository selector as the delete operation:

gh variable get EXAMPLE_VARIABLE --repo OWNER/REPO
gh variable get EXAMPLE_VARIABLE --env production --repo OWNER/REPO
gh variable get EXAMPLE_VARIABLE --org EXAMPLE_ORG

Only run the applicable line. A lookup error after deletion is expected for a name that no longer exists. If a record is still returned, check that you did not inspect a different scope, organisation or repository. Listing variables is another read-only way to confirm the target set:

gh variable list --repo OWNER/REPO
gh variable list --env production --repo OWNER/REPO
gh variable list --org EXAMPLE_ORG

Recovery if the deletion was wrong

gh variable delete has no restore operation. If you recorded the original value and still want the variable, recreate it with gh variable set at the same scope:

gh variable set EXAMPLE_VARIABLE   --body 'RECORDED_VALUE'   --repo OWNER/REPO

gh variable set EXAMPLE_VARIABLE   --body 'RECORDED_VALUE'   --env production   --repo OWNER/REPO

gh variable set EXAMPLE_VARIABLE   --body 'RECORDED_VALUE'   --org EXAMPLE_ORG

Use only the relevant form, and verify it with gh variable get. Recreating a variable is a new configuration change, not a time-travel restore: review its intended visibility and value before setting it.

Done means

  • The target variable name, repository and scope were checked before deletion.
  • The value was preserved only if an approved recovery path required it.
  • The command used the correct default, --env or --org scope.
  • The matching get or list command confirmed the post-deletion state.
  • Any recovery used gh variable set at the same scope and was verified.