Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How do you use secrets such as API keys in GitHub Actions safely?

SHORT ANSWER

Store them under repository Settings, Secrets and variables, then read them in the workflow as secrets.NAME. GitHub masks their values in logs, and they are not passed to workflows from forks by default.

Explain it simply

A key hidden under the mat is not safe; a locker with a code is. Secrets are the locker.

Add the value in the repository settings. In the workflow, reference it with ${{ secrets.API_KEY }} and pass it to a step as an environment variable. GitHub hides the value if it appears in logs, but a careless echo that transforms it can still leak it. Pull requests from forks do not receive secrets, so an attacker cannot steal them with a malicious PR. Never write the key in the YAML file.

Example

yaml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - run: ./deploy.sh
        env:
          API_KEY: ${{ secrets.API_KEY }}

What to say in the interview

"I store secrets in repository or environment settings and reference them as secrets.NAME, passing them via env. GitHub masks them in logs and withholds them from fork pull requests. I never put the value in the workflow file or print it."

#github#actions#secrets

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.