production, staging, or DemoEnvironment) let you enforce deployment protection rules (required reviewers, wait timers) and also host scoped secrets and variables. A secret name can exist at all three levels; this guide shows which value GitHub Actions will expose to your workflow when the same secret name appears in multiple scopes.
Create and configure an environment
Create an environment in your repository settings and configure protection rules such as required reviewers and wait timers. For this demonstration we created an environment namedDemoEnvironment, set a 15-minute wait timer, and required a reviewer (ourselves). We also enabled the option to allow administrators to bypass protection rules.

Add an environment-level secret
You can scope secrets specifically to an environment. For this demo we added an environment secret namedDEMO_OVERRIDE_SECRET with the value EnvironmentValue. Environment secrets are only available to jobs that declare that exact environment.
Add an organization-level secret
At the organization level (Organization → Settings → Actions → Secrets and variables → Actions → New organization secret) you can create org-wide secrets. We defined an organization secret namedDEMO_OVERRIDE_SECRET with the value OrganizationValue. Organization secrets may be restricted to specific repositories or made available org-wide.

Add a repository-level secret
At the repository level (Settings → Secrets and variables → Actions) we added a repository secret namedDEMO_OVERRIDE_SECRET with the value RepositoryValue.
When a repository has a secret with the same name as an organization secret, the GitHub UI indicates that the repository secret overrides the organization secret. That override is only relevant when the job is not associated with an environment that defines the same secret name.

Secret precedence — key points
- Environment secrets take highest precedence for jobs associated with that environment.
- If a job does not declare an environment, repository-level secrets override organization-level secrets when names conflict.
- Unique secrets defined only at one level remain available from that level.
- Environment protection rules (approvals, wait timers) can prevent a job from running until requirements are met; admins can be allowed to bypass protection rules.
Reference secrets in workflow YAML using the
secrets context. Example: env: TEST_SECRET: ${{ secrets.DEMO_OVERRIDE_SECRET }}. Put the expression inside a code block or inline code (as shown) so MDX does not interpret the curly braces.Avoid printing secret values in logs. Although GitHub masks secrets in logs, echoing secrets or writing them to files can unintentionally expose sensitive data. Use them only where necessary and handle output carefully.
Demo workflow: test precedence
This single workflow demonstrates both scenarios:- TEST 1: Job associated with
DemoEnvironment— environment-level secret should win. - TEST 2: Job with no environment — repository-level secret should win over organization-level secret.
.github/workflows/secrets-priority.yml in your repository.
Run the workflow and observe the behavior
After pushing this workflow or manually dispatching it:- The
repo-vs-orgjob will run immediately and should print that the repository-level secret won (becauseRepositoryValueoverridesOrganizationValuefor the same secret name when no environment is declared). - The
env-vs-repo-vs-orgjob will be blocked by environment protection rules (approval and wait timer). The Actions UI will show the job waiting for deployment approval and the timer.

Example run output (repo vs org)
When the job that does not use an environment runs, expected output:Summary
- Environment secrets have highest priority when a job is associated with that environment and the same secret name exists at multiple levels.
- If a job does not reference an environment, repository secrets override organization secrets when names conflict.
- Environment protection rules (approvals, wait timers) can delay or block runs until requirements are satisfied; administrators may be allowed to bypass protections.
- Use the
secretscontext (${{ secrets.YOUR_SECRET_NAME }}) in workflow YAML to access scoped secrets. Keep secret values out of logs and persistent artifacts.
Links and References
- GitHub Actions: About environments for deployment
- GitHub Actions: Encrypted secrets
- GitHub Actions: Workflow syntax for GitHub Actions