Where can secrets be defined, and what is the precedence?
BeginnerConceptSecrets, Variables, Environments & Permissions
Answer
Organization (optionally restricted to selected repos), repository, and environment. If the same name exists at several levels, the most specific wins: environment over repository over organization. Dependabot and Codespaces have their own separate secret stores. Secret names are case-insensitive, may only contain alphanumerics and underscores, and cannot start with GITHUB_.
gh secret set SLACK_WEBHOOK --body "$URL"
gh secret set DB_PASSWORD --env prod < pw.txt
gh secret set NPM_TOKEN --org devopsshack --repos shack-api,shack-web
More on Secrets, Variables, Environments & Permissions
How are secrets protected in transit and in logs, and what are the limits?IntermediateAre secrets available to every step automatically?BeginnerWhy is it a bad idea to store structured data like JSON or a whole `.env` file as one secret?IntermediateWhat is an environment, and which protection rules can it have?BeginnerWhen does a job wait for environment approval, and what does the reviewer see?IntermediateHow do deployment branch policies interact with tags and `workflow_dispatch`?Advanced