Skip to content
Discussion options

You must be logged in to vote

Hi! Great question. You should never commit your .env file to GitHub because it contains sensitive secrets.

Here is the best practice:

  1. .gitignore: Add .env to your .gitignore file immediately.
  2. .env.example: Create a file named .env.example with the keys but no real values (e.g., API_KEY=your_key_here) so others know what is needed.
  3. GitHub Secrets: Go to your repository Settings > Secrets and variables > Actions and add your secrets there.
  4. Workflow File: In your GitHub Actions YAML, access them like this:
    env:
      API_KEY: ${{ secrets.API_KEY }}

This keeps your keys safe while allowing your app to run!

Replies: 7 comments 1 reply

This comment was marked as off-topic.

This comment was marked as off-topic.

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mahmoudnajmeh
Comment options

Comment options

You must be logged in to vote
0 replies

This comment was marked as low quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development Welcome 🎉 Used to greet and highlight first-time discussion participants. Welcome to the community! source:ui Discussions created via Community GitHub templates
6 participants