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!
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 .
create a file.gitignore in your root directory and add.env file name in that.gitignore folder.After that You must untracked the.env file from git using git rm --cached.env and following that use 1. git add. 2. git commit -m " " 3. git push -u origin master. Now your.env file is remove from github repo.
您可以使用 .gitignore 文件从 repo 中排除文件: http : //git-scm.com/docs/gitignore 。
just add.env to the.gitignore file at the root of the project.
if still, you can see the.env file in git changes, you need to prevent tracking this file from git by executing the below command
git rm --cached .env
In addition to this, the gitignore will not push your sensitive data to your version control that is why when you do an ls or when listing all the files that you have in your root folder git ignore doesn't appear unless you do ls --all when inside your gitignore files add the env file by typing.env inside the gitignore
If before you did git init and then some commit push your project. now you realize that remove environmental variables for security purposes.
1st try: create.gitignore in your root project then include your file which want to ignore in GitHub repository.
if 1st one do not work,you can try this
git rm --cached.env
git add.
git commit -m "Removed.env"
git push
If u have already sent it to git hub, you can remove it by writing the following commands
git rm -r --cached .env
git add .
git commit -m 'your message'
git push
it will remove it automatically
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.