Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide .env file from Github

Tags:

I'm using dotenv for my rails project to store API keys. I have the dotenv gem in my gemfile, created a .env in the root of my app and have my API keys listed in there. However, when I push up to github, I notice that the .env file is still there. Am I missing a step? How can I hide the .env file from being uploaded to github.

Thank you!

like image 271
hidace Avatar asked Jun 07 '15 18:06

hidace


People also ask

How do I hide an env file in github?

Create a file called . gitignore in the root directory of your project (it's possible one is already there) and add . env on its own line in the file. Also, if you have already added it to your repository, then you will have to add the file to .

How do I exclude an .env file from Git?

You should use your . gitignore file to ignore the . env file.

Are .env files secure on github?

env is a secure environment config section in your projects, useful for storing API keys and app credentials.

Should .env files be in Gitignore?

env files for my backend application and the usual recommendation is to put all . env files in gitignore to not share it in the repo and use something like Github Secrets to store the . env files.


1 Answers

Create a file called .gitignore in the root directory of your project (it's possible one is already there) and add .env on its own line in the file.

Also, if you have already added it to your repository, then you will have to add the file to .gitignore as stated above and then clear Git's cache. You can find information on that in the following answer on StackOverflow.

like image 165
searsaw Avatar answered Sep 17 '22 19:09

searsaw